是否可以在 iOS 中将 UIActivityIndicatorView 颜色更改为黑色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2998131/
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
Is it possible to change an UIActivityIndicatorView color to black in iOS?
提问by Pugal
I want to change an activity indicator color gray/white to black. Is it possible to change the color to black? If yes, please guide me or give some sample code.
我想将活动指示器颜色灰色/白色更改为黑色。是否可以将颜色更改为黑色?如果是,请指导我或提供一些示例代码。
回答by Cesar
You can use the .color
property in order to change the UIActivityIndicatorView
color, e.g.:
您可以使用该.color
属性来更改UIActivityIndicatorView
颜色,例如:
// Objective-C
activityIndicator.color = [UIColor greenColor];
// Swift
activityIndicator.color = .green
Note that .color
is only available from iOS 5.
请注意,.color
仅适用于 iOS 5。
回答by user643097
You can switch between .gray
, .white
and .whiteLarge
by using the .activityIndicatorViewStyle
property.
您可以使用属性在.gray
、.white
和之间切换。.whiteLarge
.activityIndicatorViewStyle
回答by brownmagik352
I recommend doing the following:
我建议执行以下操作:
UIActivityIndicatorViewStyle.whiteLarge
to make the spinner bigger- pick a color
pick a backgroundColor to increase contrast
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge) activityIndicator.color = UIColor.<YOUR DESIRED COLOR> activityIndicator.backgroundColor = UIColor.<YOUR DESIRED BACKGROUND COLOR> self.view.addSubview(self.activityIndicator)
UIActivityIndicatorViewStyle.whiteLarge
使旋转器变大- 选择一种颜色
选择 backgroundColor 以增加对比度
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge) activityIndicator.color = UIColor.<YOUR DESIRED COLOR> activityIndicator.backgroundColor = UIColor.<YOUR DESIRED BACKGROUND COLOR> self.view.addSubview(self.activityIndicator)
回答by Sagar Patel
To use a standard system color:
要使用标准系统颜色:
activityIndicator.color = .green
To use a custom RGBA color
使用自定义 RGBA 颜色
activityIndicator.color = UIColor(displayP3Red: 255/255, green: 150/255, blue: 181/255, alpha: 255/255)
回答by M VIJAY
It is very easy in Swift 5
在 Swift 5 中很容易
@IBOutlet weak var loadingIndicator: UIActivityIndicatorView! //Declare the UIActivityIndicatorView
override func viewDidLoad() {
super.viewDidLoad()
loadingIndicator.style = .medium //Just change the indicator Style
loadingIndicator.color = .black //and change what is your indicator color
}