I'm using Xcode 8. I'm trying to add a UIButton
with Image
on left side and Title
right side. I would like to maintain distance between Image
and Title
of the UIButton
in Storyboard
. I can't see Edge
option here. Any help here is much appreciated.
Using Storyboard
Environment : XCode 8
Note : In Xcode 8 you will find the Edge
option in Size inspector which named as Content Insets, Title Insets and Image Insets.
Environment : XCode 7
Using Code.
Swift 3
myButton.titleEdgeInsets = UIEdgeInsetsMake(_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat);
myButton.imageEdgeInsets = UIEdgeInsetsMake(_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat);
Objective C
[myButton setTitleEdgeInsets:UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)];
[myButton setImageEdgeInsets:UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)];
Xcode 8 StoryBoard:
First set the title and image to the button, and go to the size inspector and set title insets and image insets, it will align the content to desired location. In your case set title inset left and image insets right.
Programatically:
button.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
button.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
Output:
Xcode 7 StoryBoard:
Xcode 7 Edge option has been moved from Attribute inspector to Size inspector section in Xcode 8, and named as Content insets, Title insets and Image insets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With