Here is my UIButton
It contains a facebook icon and it's too big so I want to resize it to this. I don't want to resize the image itself because the facebook icon is using in some place with different size and in iPad the text is bigger
I try using the code below but it only make the image height smaller, the width don't change
self.btnConnectWithFB.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
self.btnConnectWithFB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
self.btnConnectWithFB.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
What should I do to resize image for both width and height? Can I achieve it by using UIButton
or I need to create a ViewGroup
with UILabel and UIImageView
? Any help would be appreciated.
Simply resize the image itself . This is easily done in your code, when you create the button, by redrawing the image at smaller size into an image graphics context and extracting the resulting image.
By doing that, I was readily able to get the difference between these two buttons, both using the same original "f" image which I took directly from your screenshot:
Of course you can perform further tweaks if you like; a button's internal layout is highly configurable. I'm just showing you that this works. And it's trivial to do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.