How to adjust an UIButton's imageSize?

前端 未结 16 2128
时光说笑
时光说笑 2021-01-29 21:40

How can I adjust the image size of the UIButton? I am setting the image like this:

[myLikesButton setImage:[UIImage imageNamed:@\"icon-heart.png\"] forState:UICo         


        
16条回答
  •  故里飘歌
    2021-01-29 22:12

    Swift 3

    I set myButton width and height to 40 and my padding from EdgeInsetsMake is 15 all sides. I suggest to add a background color to your button to see the actual padding.

    myButton.backgroundColor = UIColor.gray // sample color to check padding
    myButton.imageView?.contentMode = .scaleAspectFit
    myButton.imageEdgeInsets = UIEdgeInsetsMake(15, 15, 15, 15)
    

提交回复
热议问题