iOS 7 中的进度视图高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18717895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:03:17  来源:igfitidea点击:

Progress view height in iOS 7

iphoneiosobjective-cios7uiprogressview

提问by Iqbal Khan

I want to increase the height of progress view in iOS 6 and below i am doing this using appearence method

我想在 iOS 6 及更低版本中增加进度视图的高度,我正在使用外观方法进行此操作

  UIImage *progressImage = [[UIImage imageNamed:@"sliderbk-progress.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 5)];
[[UIProgressView appearance] setProgressImage:progressImage];

but now in iOS7 this code is not working i even try given below code but no use. Any help will be helpfull. Thanks

但现在在 iOS7 中这段代码不起作用我什至尝试给出下面的代码但没有用。任何帮助都会有所帮助。谢谢

[[UIProgressView appearance] setFrame:CGRectMake(20, 100, 280, 100)];

回答by Derek Lee

If I am understanding the question correctly it sounds like you want to increase the height of the progress view in iOS7, and the code you used previously in iOS6 is no longer working.

如果我正确理解了这个问题,听起来您想增加 iOS7 中进度视图的高度,而您之前在 iOS6 中使用的代码不再有效。

I had to solve a similar problem recently and I did this by adding a constraint to the progress view in Interface Builder and setting the height explicitly through the constraint. This solution will require the use of Auto-Layout, so be sure that you have that turned on.

我最近不得不解决一个类似的问题,我通过向 Interface Builder 中的进度视图添加约束并通过约束显式设置高度来做到这一点。此解决方案将需要使用自动布局,因此请确保您已将其打开。

height attribute

高度属性

Shown: the "Height" attribute on the Size Inspector is visibly greyed out for a Progress View and cannot be changed - however I've defined a constraint on the Progress View itself and set the constraint's height to 50 points, which is actually reflected in IB.

显示:尺寸检查器上的“高度”属性对于进度视图明显变灰并且无法更改 - 但是我已经定义了进度视图本身的约束并将约束的高度设置为 50 点,这实际上反映在IB。

From what I've seen iOS6 Progress Bars have a static height value, so if you also want to support iOS6 then another approach will be necessary for that.

从我所看到的 iOS6 Progress Bars 有一个静态高度值,所以如果你也想支持 iOS6 那么另一种方法将是必要的。

回答by user3189408

Whereas others have reported that a CGAffineTransform() works as well:

而其他人报告说 CGAffineTransform() 也可以工作:

[self.progressView setTransform:CGAffineTransformMakeScale(1.0, 3.0)];

回答by Rushabh

Use this Code :-

使用此代码:-

 CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
 progressView.transform = transform;

回答by Kevin Kong

Here's the Swiftversion of user3189408 and Rushabh's great solutions for newer developers and swift enthusiasts like me. Tested for iOS 7+/Swift 2.0.

这是 user3189408的Swift版本和 Rushabh 为像我这样的新开发人员和Swift爱好者提供的出色解决方案。已针对 iOS 7+/Swift 2.0 进行测试。

    progressView.transform = CGAffineTransformMakeScale(1.0, 5.0)

回答by Ning

Swift 3.x

斯威夫特 3.x

progressView.transform = CGAffineTransform(scaleX: 1.0, y: 5.0)

回答by Shoaib

Already answered here How to increase height of UIProgressView

已经在这里回答 如何增加 UIProgressView 的高度

@implementation UIProgressView (customView)

- (CGSize)sizeThatFits:(CGSize)size 
{
   CGSize newSize = CGSizeMake(self.frame.size.width,9);
   return newSize;
}

@end

回答by Sulthan

You can note that framecannot be set by appearanceaccessor. You have to set it on each progress view separately.

您可以注意frame不能由appearance访问器设置。您必须分别在每个进度视图上设置它。

Usually, the height is set depending on progress bar style.

通常,高度根据进度条样式设置。

- (id)initWithProgressViewStyle:(UIProgressViewStyle)style; // sets the view height according to the style