Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No UIButton Edge option in Xcode 8

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.

like image 445
Bharath Vankireddy Avatar asked Nov 07 '16 06:11

Bharath Vankireddy


2 Answers

Using Storyboard

Environment : XCode 8

Xcode8

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

Xcode7

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)];
like image 69
Ramkrishna Sharma Avatar answered Apr 06 '23 10:04

Ramkrishna Sharma


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.

enter image description here

Programatically:

button.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
button.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right);

Output:

enter image description here

Xcode 7 StoryBoard:

enter image description here enter image description here

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.

like image 40
Jeyamahesan Avatar answered Apr 06 '23 10:04

Jeyamahesan