import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myText: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
"label. layer. masksToBounds = true" is an important code, if you apply corner radius to a label and if it dosen't work than adding this will definitely add the corner radius to a particular label.. So this should be the correct answer..
The corner radius is a measurement describing the curve on the corners of your labels. This is measured in millimetres and refers to the radius of the circle created if the curve was extended to create a full circle.
For iOS 11 onwards use Masked Corners property.
There is now a maskedCorners property for the layer. This is a CACornerMask which has four possible values for each corner:
Create an extension for better use:
extension UIView {
func roundCorners(corners:CACornerMask, radius: CGFloat) {
self.layer.cornerRadius = radius
self.layer.maskedCorners = corners
}
}
Example:
class CustomCell: UICollectionViewCell {
override func layoutSubviews() {
//Round left and righ top corners
yourView.roundCorners(corners: [.layerMinXMinYCorner, .layerMaxXMinYCorner], radius: radius)
}
}
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