mat*_*att 3 uiprogressview ios ios7
我titleView在导航项中使用进度视图(UIProgressView),以便它出现在我的导航栏中.无论我做什么,它在iOS 7.1中显得非常狭窄:

我讨厌这个版本的进度视图.怎么能让它更胖/更厚/更高?我已经尝试了这里和这里建议的一切.我已经尝试更改框架,添加转换,使用自定义子类,添加约束(这些只会导致崩溃).我曾经使用的技巧,添加了一个progressImage和trackImage,在iOS 7.1中被破坏了!
这是我的代码(整个事情发生在代码中;我在这个项目中没有笔尖或故事板):
UIProgressView* prog = [[UIProgressView alloc] init];
self.prog = prog;
self.prog.progressTintColor = [UIColor colorWithRed:1.000 green:0.869 blue:0.275 alpha:1.000];
self.prog.trackTintColor = [UIColor darkGrayColor];
self.navigationItem.titleView = prog;
Run Code Online (Sandbox Code Playgroud)
mat*_*att 10
我以一种特别棘手的方式解决了这个问题.我们已经知道提供高度约束应该有效.但只是这样做会使我的应用程序崩溃.最后我有一个头脑风暴.我使用另一个视图作为我titleView,并将进度视图放在其中.现在我能够应用适当的约束:
UIProgressView* prog = [[UIProgressView alloc] init];
self.prog = prog;
self.prog.progressTintColor = [UIColor colorWithRed:1.000 green:0.869 blue:0.275 alpha:1.000];
self.prog.trackTintColor = [UIColor darkGrayColor];
self.prog.translatesAutoresizingMaskIntoConstraints = NO;
CGFloat w = 150;
CGFloat h = 10;
[self.prog addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:w]];
[self.prog addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeHeight relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:h]];
UIView* v = [[UIView alloc] initWithFrame:CGRectMake(0,0,w,h)];
[v addSubview:self.prog];
[v addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeCenterX relatedBy:0 toItem:v attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[v addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:v attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
v.clipsToBounds = YES;
v.layer.cornerRadius = 4;
self.navigationItem.titleView = v;
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我也利用这个来为角落添加一些圆角.我认为结果非常漂亮.

| 归档时间: |
|
| 查看次数: |
3391 次 |
| 最近记录: |