I know that in iOS 3.0+ I can use
label.layer.cornerRadius = xxx;
to round all four corners of a UILabel (as a UIView subclass), but I want to round only the top two corners of the label and keep the bottom corners right-angled.
Is there any way I can do that with a UILabel? Other solutions assume a custom UIView, not a UILabel.
I have checked the Class Reference for UIView & UILabel and its layers, but could not find any way to do this with the means given by the iOS.
You could do one thing, create a
UIView
& apply rounded corners to it. Now add aUILabel
as a subview to this UIView & position it in such a way so that the bottom 2 rounded corners are covered by the label. This way you get the effect you need...Thought I would post the full code with the BezierPath included.
For Swift 4.0:
You can do this using CALayers and masks
where maskPath is a UIBezierPath set up using
bezierPathWithRoundedRect:byRoundingCorners:cornerRadii