【问题标题】:UIProgressView displaying issues in iOS 7UIProgressView 在 iOS 7 中显示问题
【发布时间】: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


【解决方案1】:

今天遇到了同样的问题,解决起来并不难:)

在界面生成器中添加一个与 UIProgressView 大小完全相同的 UIView。在这个新的 UIView 中添加你的 UIProgressView。

如果您想要角落,请为您的 UIView 执行以下操作:

1)将cornerradius设置为高度的一半(例如30px高度进度条意味着15px圆角半径UIVIew))

myView.layer.cornerRadius = 15; 

2) 将掩码设置为边界

myView.layer.masksToBounds = TRUE;

3) 将剪辑设置为边界,以便 UIView 中不会出现任何内容

myView.clipsToBounds = TRUE;

现在你有一个圆形的 UIProgressBar 和你想要的高度。

如果您不想要圆角,只需以相同的方式添加 UIView,但只需将背景颜色更改为与 UIProgressbar tracktint 相同的灰色。

祝你好运!

-Sjoerd

【讨论】:

【解决方案2】:

供将来参考:我通过设置圆角半径解决了这个问题

  _progressView.layer.cornerRadius = 2.0;

然后:

  _progressView.clipsToBounds = YES;

UIProgressView 不需要容器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多