Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

ios - Changing activity indicator color to black

I'm trying to change my activity indicator to a custom color like black. However it does not seem to apply at all and has the standard white color still.

What i've done is creating a UIView and and added a activity indicator as a subView and then added this to the tableFooterView.

How can I change the activity indicator color?

ViewDidLoad:

    let footerView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, 40))
    footerView.backgroundColor = UIColor(rgba: "#f6f7f9")
    var actInd: UIActivityIndicatorView = UIActivityIndicatorView()
    actInd.color = UIColor.blackColor()
    actInd.frame = CGRectMake(self.view.frame.size.width/2-10, 0.0, 20.0, 20.0);

    actInd.activityIndicatorViewStyle =
        UIActivityIndicatorViewStyle.WhiteLarge
    footerView.addSubview(actInd)
    actInd.startAnimating()
    self.tableVIew.tableFooterView = footerView
question from:https://stackoverflow.com/questions/29698272/changing-activity-indicator-color-to-black

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to set the color after you set the activity indicator style. It seems that setting the activityIndicatorViewStyle resets the color for the activityIndicator

So just do this:

// .... 

activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
activityIndicator.color = .black
footerView.addSubview(activityIndicator)
activityIndicator.startAnimating()
self.tableView.tableFooterView = footerView

This should work just fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...