-1

I want to make the label's backround full circle.

i searched and find out

numLabel.layer.masksToBounds = true
numLabel.layer.cornerRadius = numLabel.bounds.width / 2

on iphone it is fine on ipad, firsttime it is just a corner radius rectangle, when i move tableview up and down, in anotherwords, cell view gets out of the main view and gets back in, it becomes a fine circle.

i wonder, what is the mistake i am doing ?

edit : numLabel is inside TableViewCell / TableViewController / NavigationController / splitViewController and it has its own tableViewCell class. and that code is run From layoutsubviews() numlabel width and height is equal by contraints

Recep Bala
  • 19
  • 1
  • 5
  • Where did you put this code? – Sweeper May 19 '20 at 14:41
  • `numLabel.layer.cornerRadius = numLabel.bounds.width / 2` will make label circle only if width and height of label are same, else it will make oval or rounded corner rectangle, Labels have intrinsic size and the width and height changes as per content inside it or based on constraint applied to it, make sure you have enough constraint to ensure label will be square all the time (width == height) – Sandeep Bhandari May 19 '20 at 14:45
  • updated the question... – Recep Bala May 19 '20 at 17:38

1 Answers1

0

you should never call layoutSubViews directly

override layoutSubViews, don't forget to call super and then put your code there.

farhad
  • 430
  • 2
  • 8