Search code examples
ioscollectionview

Cannot round corners of labels in a Custom Collection View Cell in iOSSwift


Please can you help out with a query. I am using Xcode (11.5), iOS Single Page App. I have built a custom collection view cell that displays an image, label and button.

In the custom cell class, I have a function that updates the layer properties of the objects e.g.

button.layer.cornerRadius = 5
label.layer.cornerRadius = 5. 

When I run the code, only the button's corners are rounded. The label's corner doesn't get update. I can change the background color of the label but not the corner radius.

Also the borderWidth as well for the label doesn't change.


Solution

  • 'label.layer.masksToBounds = true'