开发者

How to center a UIImage to UIButton?

开发者 https://www.devze.com 2023-02-22 13:54 出处:网络
I want to know how to center a UIImage to UIButton. I am using the setImage method of开发者_StackOverflow中文版 UIButton to place the UIImage..You can use the contentMode Property:

I want to know how to center a UIImage to UIButton. I am using the setImage method of开发者_StackOverflow中文版 UIButton to place the UIImage..


You can use the contentMode Property:

button.imageView.contentMode = UIViewContentModeCenter;


Remove the text from the UIButton before setting the content mode


Sometimes you might have the wrong content alignment. Make sure they are both in the center with :

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号