Kokolo
Kokolo

Reputation: 260

Two identical CGSize's and one appears smaller

I have an ImageView and I have a CustomView that I want to appear the same size on screen.

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
progress.frame.size = circle.frame.size
print("Progress frame size w: \(progress.frame.size.width) h: \(progress.frame.size.height)
print("Circle frame size w: \(circle.frame.size.width) h: \(circle.frame.size.height)

//Progress frame size w: 300 h: 300
//Circle frame size w: 300 h: 300

and yet they appear with different size on the Simulator:

enter image description here

I tried setting the bounds instead of frame. I also tried calculating the difference from the view to the circle and setting the progress frame according to that:

let widthDifference = UIScreen.main.bounds.width - circle.frame.size.width
let progressWidth = UIScreen.main.bounds.width - widthDifference
...

but no success.

I don't know what's happening, I am really new to iOS development and many things are weird to me.

The size of the progress bar was fine when the scene was wrapped in a NavigationController. When I removed the NavigationController the dimensions were totally screwed.

FYI: Circle is an image view. Progress is a third-party circular progress bar

Thank you for your time!

Upvotes: 0

Views: 70

Answers (1)

Fangming
Fangming

Reputation: 25261

Your progress bar is indeed the same size of your circle but that doesn't mean that the bar will take the full size of 300px for diameter.

If you are curious, take a look at this line from the library, and also this line to see how the radius is created.

You can also try to print out the value of arcRadius and it must be smaller than 150px.

Upvotes: 1

Related Questions