iOS: frame.size.width/2 doesn't produce a circle on every device

后端 未结 6 1420
长发绾君心
长发绾君心 2020-11-29 06:09

I\'m aware that the formulae frame.size.width/2 should produce a circle border, however in XCode I am currently experiencing some discrepancies.

I have

6条回答
  •  春和景丽
    2020-11-29 06:55

    Well, Autolayout should be the issue. As it can be seen the height of the imgAvatar on right is greater than the height of the imgAvatar on left.

    The size of imgAvatar on right is 190 x 190 and the one on left is 200 x 200, but on the left the corner radius which you are setting is 190/2 i.e. 95px whereas it should be 100px.

    Kindly set Height & Width Constraint in your nib file for imgAvatar, if you do not want the imgAvatar to resize by 1:1.

    1. Select imgAvatar in your nib.
    2. Editor > Pin > Height
    3. Select imgAvatar in your nib.
    4. Editor > Pin > Width

    OR

    Try moving your code to viewDidLayoutSubviews

    OR

    Subclass your UIImageView and set its corner radius in its awakeFromNib method

    Kindly let us know if it worked. Thanks!

提交回复
热议问题