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;
精彩评论