I have labels that I want to round the corners of in Swift, the labels are created in the Xcode storyboard. The solution I was using at first was:
label.layer.masksToBounds = true
label.layer.cornerRadius = 8.0
Though with this solution, it rounds all corners instead of just the top left and bottom left.
I looked around Stackoverflow, and came up with the following solution to round only the top left and bottom left corners:
let bounds: CGRect = label.bounds
let maskPath = UIBezierPath(roundedRect: bounds,
byRoundingCorners: ([.topLeft, .bottomLeft]),
cornerRadii: CGSize(width: 8.0, height: 8.0))
let maskLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = maskPath.cgPath
label.layer.mask = maskLayer
I have also attempted to enable maskToBounds here, with no result.
Now this solution works for only rounding the two corners that I want to round, though the label no longer follows the constraints I was using for the UI unlike with the first solution which worked with my UI constraints.
For layout I am using stack views, to stack the label with a button next to it horizontally, and then each pair is placed in a vertical stack view to stack four pairs on top of each other. After making the change to the second solution, the label now cuts off short of the button next to it that it is supposed to match in height.
First solution:
Second solution:
I'd appreciate a detailed answer as I am relatively new to Swift and am interested in learning what the issue is.