Reputation: 83
I am trying to add an imageview as a circle in swift to a uiview. I call the following code in swift however it creates the image to appear briefly incorrectly before it is corrected to a circle
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
theirPicMaskFour.layer.cornerRadius = theirPicMaskFour.frame.height / 2
theirPicMaskFour.layer.masksToBounds = false
theirPicMaskFour.layer.borderWidth = 0;
theirPicMaskFour.clipsToBounds = true
}
The following is the way it looks initially.
The following is how it looks after.
Upvotes: 0
Views: 124
Reputation: 122
Try
theirPicMaskFour.layer.cornerRadius = theirPicMaskFour.frame.size.width / 2
instead of
theirPicMaskFour.layer.cornerRadius = theirPicMaskFour.frame.height / 2
Upvotes: 1
Reputation: 5957
Try theirPicMaskFour.layer.masksToBounds = true
and log out the height before u assign just to be sure that the height isn't something out of ordinary
[EDIT]
Alloc and init it in viewDidLoad
but update the round rect in viewDidLayoutSubviews
as it will be called multiple times, but changes on frames wont effect it as that will remain same.
Upvotes: 0