How to adjust an UIButton's imageSize?

前端 未结 16 2100
时光说笑
时光说笑 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:26

    Swift 4

    You would need to use these two lines of code, in this specific order. All you need is to change the top and bottom value of the edge insets.

    addButton.imageView?.contentMode = .scaleAspectFit
    addButton.imageEdgeInsets = UIEdgeInsetsMake(10.0, 0.0, 10.0, 0.0)
    

提交回复
热议问题