开发者

How to center a UIImage to UIButton?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜