Why does a custom UIButton image does not resize in Interface Builder?

前端 未结 10 1227
你的背包
你的背包 2020-12-24 00:45

Why does a custom UIButton image not resize with the button?

I set its view mode to Scale to Fill in Interface Builder, but unlike a UIImageView image, it d

10条回答
  •  余生分开走
    2020-12-24 01:26

    I know this is old, but I think that the correct answer is that you should set the content mode to the "hidden" UIImageView that is inside the UIButton:

    button.imageView.contentMode = UIViewContentModeScaleAspectFill;
    

    This will change the content mode for the images views of the images set with:

    [button setImage:yourAwesomeImage forState:UIControlStateNormal]; 
    //Or any other state
    

提交回复
热议问题