1

Currently the label displayed has a custom radius set for the top right and bottom right corners. However the background color the the label is not filling entirely.

Have attempted to set the layers maskToBounds property to true and false. Attempted changing both the dateLabel.backgroundColor and dateLabel.layer.backgroundColor to the desired dark blue color programmatically that is defaulted in the storyboard in an attempt to refill the label with no success.

@IBOutlet weak var dateLabel: UILabel! { didSet { 
    dateLabel.round(corners: [.topRight, .bottomRight], radius: 15, borderColor: UIColor.cyan, borderWidth: 3.0)
    dateLabel.setNeedsLayout()
}}

override func viewDidLayoutSubviews() {
    dateLabel.layoutIfNeeded()
}

override func viewDidLoad() {
    super.viewDidLoad()
    dateLabel.layer.backgroundColor = UIColor.blue
}

enter image description here

What could be the reason for a label not filling its view entirely and what solution is available?

lifewithelliott
  • 1,012
  • 2
  • 16
  • 35

1 Answers1

1

The problem is definitely the use of corner function, it adds sublayers to your UIlable , each sublayer has it's own background colour, so you can either find another way of rounding corners without using that function which adds sublayers or in your viewDidLoad iterate through sublayers property of layer layer.sublayers which is an array of sublayers and apply your background colour to each of them, or add a function to that UIView extension ( corner function ) that does this king of colour assignment then call that function.

Rhm Akbari
  • 362
  • 3
  • 12