我想将活动指示器的颜色从灰色/白色变为黑色。是否可以将颜色更改为黑色?如果可以,请指导我或给出一些示例代码。
我想将活动指示器的颜色从灰色/白色变为黑色。是否可以将颜色更改为黑色?如果可以,请指导我或给出一些示例代码。
您可以使用 .color
属性来更改 UIActivityIndicatorView
的颜色,例如:
// Objective-C
activityIndicator.color = [UIColor greenColor];
// Swift
activityIndicator.color = .green
请注意,.color
属性仅在 iOS 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
}
使用标准系统颜色:
activityIndicator.color = .green
使用自定义RGBA颜色
activityIndicator.color = UIColor(displayP3Red: 255/255, green: 150/255, blue: 181/255, alpha: 255/255)
UIActivityIndicatorViewStyle.whiteLarge
to make the spinner biggerpick 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)