【发布时间】:2013-12-18 08:05:26
【问题描述】:
我需要 UIProgressView 作为一个 iOS 7 应用程序的 UITableView 单元格的一部分。我从单元格右侧的代码中添加了 UIProgressView,如下所示:
_progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressBar.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_progressBar];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_progressBar attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_progressBar attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10.0]];
[_progressBar addConstraint:[NSLayoutConstraint constraintWithItem:_progressBar attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:60.0]];
[_progressBar addConstraint:[NSLayoutConstraint constraintWithItem:_progressBar attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:12.0]];
但是,显示 UIProgressView 有点奇怪。当进度为零时,UIProgressView 对象如下所示:
当我将进度值设置为 0.5 时,UIProgressView 左侧变为矩形,右侧保持圆角矩形:
当我将进度设置为 0.98 时,看起来像这样:
知道如何通过简单地设置进度值来填充 UIProgressView 并且始终保留圆角矩形(或矩形)形式的元素吗?或者如果不添加自定义图形或覆盖 UIProgressView,这是不可能的吗?
非常感谢提前和最好的问候。
【问题讨论】:
-
我认为 UIProgressView 的高度是固定的。
-
progressview的高度可以改变,最好用CGAffineTransform来做
标签: ios iphone objective-c ios7 uiprogressview