How do I round the corners of my Activity Indicator Background
Asked Answered
K

1

6

I am BRAND NEW to coding. With that said, I have figured out how to put a grey background behind my white activity indicator spinner. Now I want the corners of the background to be rounded. I have searched and searched but I'm not having success.

Here is the code I am using to display the activity indicator and background. If you need more information to help, just ask. I don't really know how to even ask the question. I'm a total rookie.

activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 80, 80))

activityIndicator.center = self.view.center

activityIndicator.backgroundColor = (UIColor (white: 0.3, alpha: 0.8))   //create a background behind the spinner

activityIndicator.hidesWhenStopped = true

activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge

view.addSubview(activityIndicator)

activityIndicator.startAnimating()

UIApplication.sharedApplication().beginIgnoringInteractionEvents()
Kroll answered 7/4, 2015 at 23:28 Comment(0)
D
11

Welcome to Stack Overflow!

In answer to your question: you should set the CALayer property cornerRadius to a positive, non-zero value. For example:

activityIndicator.layer.cornerRadius = 10

And the result:

enter image description here

Also, since you're totally new to programming I would recommend you check out Apple's The Swift Programming Language, it's free and takes you through the whole Swift language. Here's the link: https://itunes.apple.com/gb/book/swift-programming-language/id881256329?mt=11 (It's also available just as a Web version)

Discover answered 7/4, 2015 at 23:37 Comment(2)
Thank you for you feedback. First, I have the swift programming language book from iTunes. I find it difficult to follow but I can see where it will be helpful as I learn more. The code you suggested was what I tried first but it is not rounding the corners so I thought I had written the wrong code. Is there a specific place I have to put this cornerRadius code or can it go anywhere after I draw the frame?Kroll
Sorry. I just realized I have been putting this cornerRadius code in the part of the code that is supposed to actually show the activity indicator when the app is running. I had also put in a test button (pause) to run the activitIndicator any time I wanted to so I could test the code I was writing. Again, I'm new to this and I get easily confused. Thanks again for you help and I'm sure I will be back again for more.Kroll

© 2022 - 2024 — McMap. All rights reserved.