How can I set UIButton image, which Image is round shape with border

后端 未结 6 1578
难免孤独
难免孤独 2021-01-24 04:04

How can I set UIButton image, which Image is round shape with border I write related code but image not displaying in proper round shape.. Here is my code..

             


        
6条回答
  •  时光取名叫无心
    2021-01-24 04:33

    set clipsToBounds = true for your imageview

    btnMyProfile.imageView.clipsToBounds = true
    

    or use

    btnMyProfile.imageView.layer.masksToBounds = true
    

    From the apple docs:

    By default, the corner radius does not apply to the image in the layer’s contents property; it applies only to the background color and border of the layer. However, setting the masksToBounds property to true causes the content to be clipped to the rounded corners.

    else another option use UIBezierPath

提交回复
热议问题