UIProgressView의 높이를 높이는 방법
UIProgressView
에서 만들고 있습니다 nib
. 높이를 늘리고 싶지만 9로 고정되어 iPad
있습니다. 높이를 늘려야하기 때문입니다. 어떻게 할 수 있습니까?
미리 감사드립니다.
nib을 통해 UIProgressView의 높이를 사용할 수 없습니다. 높이를 변경하여 사용자 정의 그리기 방법을 통해 구현해야합니다.
CGAffineTransform을 사용하여 차원 변경 :
CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 3.0f);
progressView.transform = transform;
레이아웃 제약 조건을 사용하면 저에게 딱 맞습니다.
이 소스 배치
@implementation UIProgressView (customView)
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(self.frame.size.width, 9);
return newSize;
}
@end
초기화 된 후 코드에서 UIProgressView의 프레임을 설정하기 만하면됩니다. 예 :
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
// progressView's frame will be small/standard height
progressView.frame = CGRectMake(0, 0, 100, 20);
// Now the frame is set to my custom rect.
이것은 iOS 5에서 저에게입니다. 저는 사용자 정의 trackImage와 progressImage를 사용하고 있습니다. 내 코드는 다음과 달라집니다. progressView를 다른 뷰에 추가하고 포함하는 뷰와 동일한 크기를 원 프레임에 self.bounds로 설정합니다.
_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_progressView.trackImage = [[UIImage imageNamed:@"search-progress-track"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0f, 3.0f, 3.0f, 3.0f)];
_progressView.progressImage = [[UIImage imageNamed:@"search-progress"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0f, 3.0f, 3.0f, 3.0f)];
_progressView.frame = self.bounds;
[_progressView setProgress:0.5];
Interface Builder 내에서 높이를 변경하는 간단한 방법이 있습니다. 코드가 필요하지 않게 변경 사항이 IB에 표시됩니다.
스토리 보드 또는 xib에서 UIProgressView 개체를 선택하고 편집기> 핀> 높이를 선택합니다. 이렇게하면 제약이 생성되고 가장 왼쪽에있는 패널의 속성 Inspector에서 값을 사용할 수 있습니다.
다음 코드는 최신 swift xCode에서 작동합니다.
var transform : CGAffineTransform = CGAffineTransformMakeScale(1.0, 6.0)
progressView.transform = transform
스위프트 3 :
progressView.transform = progressView.transform.scaledBy(x: 1, y: 9)
Swift3
var transform : CGAffineTransform = CGAffineTransform(scaleX: 1.0, y: 6.0)
progressBar.transform = transform
추가
IBDesignable
수업에서 작업하는 경우 스토리 보드에서 다음과 같이 사용할 수 있습니다.
@IBInspectable var progressBarHeight: CGFloat = 2.0 {
didSet {
let transform = CGAffineTransform(scaleX: 1.0, y: progressBarHeight)
self.progressView.transform = transform
}
}
여기에 해결책이 있습니다.
변형을 사용할 수 있습니다. 기기의 방향을 변경하면 UIProgressView가 원래대로 문제가 발생합니다.
따라서 UIProgressView 높이를 높이는 가장 좋은 방법은
yourProgressView.progressImage=[UIImage imageNamed:@"image1.png"];
yourProgressView.trackImage = [UIImage imageNamed:@"image2.png"];
// IMPORTANT: image1/image2 height (in pixel) = height that you want for yourProgressView.
// no need to set other properties of yourProgressView.
감사합니다
AutoLayout을 사용하여 동일한 모양을 사용하여 iOS 7.1에서 작동합니다. 진행률 표시 줄을 원하는 높이와 동일한 높이 제한을 추가하기 만하면됩니다. 자세한 내용은 질문에 대한 답변을 확인하십시오.
https://stackoverflow.com/a/19606981/142358
iOS 7 이상에서는 Core Graphics 및 CATransform3DScale 을 사용 하여 해당보기에서 레이어의 크기를 조정합니다.
CATransform3D transform = CATransform3DScale(progressView.layer.transform, 1.0f, 3.0f, 1.0f);
progressView.layer.transform = transform;
이전이 아니라 progressView의 프레임을 설정 한 후에이 작업을 수행해야합니다 .
iOS 7 이상에서는 (a) 작동하고 (b) 경고를 생성하지 않는 다음을 수행했습니다.
먼저 UIProgressView
스토리 보드의 뷰 컨트롤러에 추가 합니다. 그런 다음 UIProgressView
CTRL +하여 드래그 UIProgressView
에 높이 제약보기 조건을 추가 합니다. 제약 조건은 하나에서 생성 2
됩니다. 내버려둬.
이제 높이를 변경하려는 다음 과 같은 코드 IBOutlet
에서 UIViewController
하위 클래스에 를 추가합니다 .
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *progressHeight;
그런 다음 코드에서 아마도 다음을 - viewDidLoad
추가하십시오.
self.progressHeight.constant = 9;
이것은 당신을 위해 잘 작동 할 것입니다.
다음은 높이를 접근 할 수 있습니다. https://github.com/yannickl/YLProgressBar
코드 또는 인터페이스 빌더를 통해 프레임을 설정합니다. 하지만 애니메이션이나 줄무늬를 줄 수 있습니다.
다음은 향상된 녹색 진행률 표시 줄에 대한 코드입니다.
YLProgressBar *bar = [[YLProgressBar alloc] initWithFrame:CGRectMake(0, 100, 100, 50)];
bar.progress = 0.5;
bar.type = YLProgressBarTypeFlat;
bar.hideStripes = YES;
bar.behavior = YLProgressBarBehaviorDefault;
bar.progressTintColors = @[[UIColor greenColor], [UIColor greenColor]];
(새 파일-범주)를 구현하고 클래스 시작 부분에 범주 범주를 추가 할 수 있습니다. iboutlet (nib / storyboard) 작동이 잘됩니다.
코드는
@interface UIProgressView (heavyView)
@end
@implementation UIProgressView (heavyView)
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize newSize = CGSizeMake(size.width, 9);
return newSize;
}
@end
하나의 progressView에 대한 변경 사항을 적용하고 클래스에 progressView가 둘 이상있는 경우 대신 하위 클래스를 사용할 수 있습니다.
Mayur의 방법은 iOS 7에서 잘 작동했습니다. 여기 내 코드가 있습니다 (UIImage + BBlock 사용).
CGFloat progressViewHeight = 5;
[[UIProgressView appearance] setProgressImage:[UIImage imageForSize:CGSizeMake(1, progressViewHeight) withDrawingBlock:^{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor * colortoUse = [UIColor blueColor];
CGContextSetFillColorWithColor(context, [colortoUse CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, 1, progressViewHeight));
}]];
[[UIProgressView appearance] setTrackImage:[UIImage imageForSize:CGSizeMake(1, progressViewHeight) withDrawingBlock:^{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor * colortoUse = [UIColor progressViewBackgroundColor];
CGContextSetFillColorWithColor(context, [colortoUse CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, 1, progressViewHeight));
}]];
인터페이스 빌더를 사용하는 대신 UIProgressView
프로그래밍 방식으로 제약 조건을 추가 하여 높이를 변경할 수 있습니다.
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.translatesAutoresizingMaskIntoConstraints = NO;
CGRect frame = CGRectMake(100, 200, 200, 50);
[self.view addSubview:progressView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-y-[progressView(height)]" options:0
metrics:@{@"y": @(CGRectGetWidth(frame)),
@"height": @(CGRectGetHeight(frame))}
views:NSDictionaryOfVariableBindings(progressView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-x-[progressView(width)]" options:0
metrics:@{@"x": @(CGRectGetMinX(frame)),
@"width": @(CGRectGetWidth(frame))}
views:NSDictionaryOfVariableBindings(progressView)]];
내 제안은 자동 레이아웃의 뷰 컨트롤러 뷰에 컨테이너 뷰를 배치하는 것입니다. 진행률 표시 줄에 원하는 크기인지 확인하십시오. 이제 컨테이너 내부의 진행률보기를 드래그하고 모든면을 컨테이너 경계에 고정합니다. 컨테이너의 경계에 맞게 진행률보기 크기가 즉시 조정되는 것을 볼 수 있습니다.
하위 클래스를 만들고 고유 크기를 조정하십시오.
class FatProgressView: UIProgressView {
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: 20.0)
}
}
UIProgressView
.NET Framework를 서브 클래 싱하여 ProgressView의 사용자 정의 클래스를 생성 하여 높이를 설정할 수 있습니다 UIProgressView
.
스위프트에서는
public class ProgressView: UIProgressView {
var height: CGFloat = 4.0
public override func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width: size.width, height: height) // We can set the required height
}
}
단순한. 스위프트 4.
progressBar.transform = CGAffineTransform (scaleX : self.view.frame.width / progressBar.frame.width, y : self.view.frame.height / progressBar.frame.height)
참고 URL : https://stackoverflow.com/questions/3437564/how-to-increase-height-of-uiprogressview
'ProgramingTip' 카테고리의 다른 글
SQL Server 데이터베이스에서 모든 저장 프로 시저를 한 번에 삭제하는 방법은 무엇입니까? (0) | 2020.12.09 |
---|---|
JavaScript를 통해 라디오 버튼 그룹의 값을 확인 하시겠습니까? (0) | 2020.12.09 |
패딩 영역없이 div를 배경으로하는 방법 (0) | 2020.12.09 |
Android WebView가 터치 이벤트를 소비하는지 확인 (0) | 2020.12.09 |
Android에서 개발하는 데 사용할 수있는 프로그래밍 언어는 무엇입니까? (0) | 2020.12.09 |