ios 我可以更改 UIActivityIndicator 的大小吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2638120/
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
Can I change the size of UIActivityIndicator?
提问by wolverine
Whatever size i give to it while allocation, it shows fixed size only. Is it possible to increase it?
无论我在分配时给它什么大小,它都只显示固定大小。可以增加吗?
Code:
代码:
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:
CGRectMake(142.00, 212.00, 80.0, 80.0)];
[[self view] addSubview:activityIndicator];
[activityIndicator sizeToFit];
activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
activityIndicator.hidesWhenStopped = YES;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
采纳答案by TechZen
The size is fixed by the style. It's a standardized interface element so the API doesn't like to fiddle with it.
大小由样式固定。它是一个标准化的接口元素,因此 API 不喜欢摆弄它。
However, you probably could do a scaling transform on it. Not sure how that would affect it visually, however.
但是,您可能可以对其进行缩放转换。但是,不确定这会如何影响它的视觉效果。
Just from a UI design perspective, its usually better to leave these common standardized elements alone. User have been taught that certain elements appear in a certain size and that they mean specific things. Altering the standard appearance alters the interface grammar and confuses the user.
仅从 UI 设计的角度来看,通常最好不要理会这些常见的标准化元素。用户已经被告知某些元素以特定大小出现并且它们意味着特定的事物。改变标准外观会改变界面语法并使用户感到困惑。
回答by Andrew Vilcsak
The following will create an activity indicator 15px wide:
以下将创建一个 15px 宽的活动指示器:
#import <QuartzCore/QuartzCore.h>
...
UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
activityIndicator.transform = CGAffineTransformMakeScale(0.75, 0.75);
[self addSubview:activityIndicator];
While I understand the sentiment of TechZen's answer, I don't think adjusting the size of a UIActivityIndicator by a relatively small amount is really a violation of Apple's standardized interface idioms - whether an activity indicator is 20px or 15px won't change a user's interpretation of what's going on.
虽然我理解 TechZen 回答的情绪,但我不认为将 UIActivityIndicator 的大小调整相对较小的量确实违反了 Apple 的标准化界面习惯用法——活动指示器是 20px 还是 15px 不会改变用户的解释发生了什么。
回答by Harshil Kotecha
Swift 3.0 & Swift 4.0
斯威夫特 3.0 和斯威夫特 4.0
self.activityIndi.transform = CGAffineTransform(scaleX: 3, y: 3)
回答by vntstudy
It is possible to resize UIActivityIndicator.
可以调整 UIActivityIndicator 的大小。
CGAffineTransform transform = CGAffineTransformMakeScale(1.5f, 1.5f);
activityIndicator.transform = transform;
Original size is 1.0f. Now you increase and reduce size accordingly.
原始尺寸为 1.0f。现在您可以相应地增加和减少尺寸。
回答by Vimal Saifudin
Swift3
斯威夫特3
var activityIndicator = UIActivityIndicatorView()
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
let transform: CGAffineTransform = CGAffineTransform(scaleX: 1.5, y: 1.5)
activityIndicator.transform = transform
activityIndicator.center = self.view.center
activityIndicator.startAnimating()
self.view.addSubview(activityIndicator)
回答by CodeBender
Here is an extension that would work with Swift 3.0& checks to prevent 0 scaling (or whatever value you want to prohibit):
这是一个可与Swift 3.0一起使用的扩展并检查以防止 0 缩放(或任何您想禁止的值):
extension UIActivityIndicatorView {
func scale(factor: CGFloat) {
guard factor > 0.0 else { return }
transform = CGAffineTransform(scaleX: factor, y: factor)
}
}
Call it like so to scale to 40 pts (2x):
像这样调用以缩放到 40 pts (2x):
activityIndicatorView.scale(factor: 2.0)
回答by Valeriy
There also are lots of other useful "CGAffineTransform" tricks you can play with. For more details please see Apple Developer Library reference:
您还可以使用许多其他有用的“CGAffineTransform”技巧。有关更多详细信息,请参阅 Apple Developer Library 参考:
Good luck!
祝你好运!
回答by wsgeorge
The best you can do is use the whiteLarge
style.
let i = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
.
您能做的最好的事情就是使用whiteLarge
样式。
let i = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
.
Increasing the size of UIActivityIndicatorView
does not change the size of the indicator proper, as you can see in these pictures.
回答by MD SHAHNAWAZUL HAQUE
indicator.transform = CGAffineTransform(scaleX: 1.75, y: 1.75);
indicator.transform = CGAffineTransform(scaleX: 1.75, y: 1.75);
This worked me for transforming size of indicator .
这对我转换指标的大小很有用。