I create UIView Extension with @IBInspectable to set corner radius but when I just rotate my device its not working properly
import UIKit
import Foundation
extension UIView {
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
}
I took image view with following constraints
when I run app in portrait mode, output will be
but its not work when i rotate my device
Set the corner radius in layoutSubviews
method.
If you need the view in circular shape, set corner radius as it's half width/height.
view.layer.cornerRadius = view.frame.width / 2.0
I can see in your screen Shot you are providing fixed corner radius
enter image description here
also providing equal width or height to superview with multiplier so that when you rotate dimensions of UIView changed and you got this result.
you need to reset the corner radius of the view when orientation changes in self.layoutSubviews()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With