是否可以在 iOS 中将 UIActivityIndi​​catorView 颜色更改为黑色?

声明:本页面是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

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

Is it possible to change an UIActivityIndicatorView color to black in iOS?

iosiphoneuiactivityindicatorview

提问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 .colorproperty in order to change the UIActivityIndicatorViewcolor, e.g.:

您可以使用该.color属性来更改UIActivityIndicatorView颜色,例如:

// Objective-C
activityIndicator.color = [UIColor greenColor];

// Swift
activityIndicator.color = .green

Note that .coloris only available from iOS 5.

请注意,.color适用于 iOS 5

回答by user643097

You can switch between .gray, .whiteand .whiteLargeby using the .activityIndicatorViewStyleproperty.

您可以使用属性在.gray.white和之间切换。.whiteLarge.activityIndicatorViewStyle

回答by brownmagik352

I recommend doing the following:

我建议执行以下操作:

  1. UIActivityIndicatorViewStyle.whiteLargeto make the spinner bigger
  2. pick a color
  3. 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)
    
  1. UIActivityIndicatorViewStyle.whiteLarge使旋转器变大
  2. 选择一种颜色
  3. 选择 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
}