gpt4 book ai didi

ios - 创建方形而不是圆形边缘效果 UIProgressView

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:03:39 24 4
gpt4 key购买 nike

我有一个 UIProgressView,我试图使它具有方形而不是圆形边缘。我没有看到任何明显的方法来做到这一点,所以我的想法是让进度图像本身比它的方形框架大一点,这样进度图像就会被裁剪成方形。但是,无论我如何改变进度图像的大小,我似乎都无法实现这种效果。谁能告诉我是否有办法实现我的目标?

这是我目前在 UIView 子类中拥有的内容:

self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
self.progressView.trackImage = [PLStyle imageForColor:[PLColors greyLight] inFrame:CGRectMake(0, 0, 1, ProgressViewHeight)];
self.progressView.progressImage = [PLStyle imageForColor:[PLColors orange] inFrame:CGRectMake(0, 0, 1, ProgressViewHeight)];

[self.progressView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:self.progressView];

[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.progressView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.imageView
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:LeadingOrTrailingSpace]];

[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.progressView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0]];

[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.progressView
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.counter
attribute:NSLayoutAttributeLeading
multiplier:1
constant:-LeadingOrTrailingSpace]];

[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.progressView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:ProgressViewHeight]];

//上面用于在进度 View 中创建图像的方法定义

+ (UIImage *)imageForColor:(UIColor *)color inFrame:(CGRect)rect
{
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

最佳答案

设置UIProgressViewStylebar

Objective-C :

[progressView setProgressViewStyle: UIProgressViewStyleBar];

swift :

progressView.progressViewStyle = .bar

关于ios - 创建方形而不是圆形边缘效果 UIProgressView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26238840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com