UIButton Text Margin / Padding

PartySoft picture PartySoft · Mar 19, 2011 · Viewed 50.3k times · Source

I have the following layout, and I'm trying to add a padding to the left and right..

The controls are a disabled UIButton.

enter image description here

My code for creating a button is this:

UIButton *buttonTime = [[UIButton alloc] initWithFrame:CGRectMake(90, 10, 50, 20)]; 
[buttonTime setBackgroundImage:[[UIImage imageNamed:@"bubble.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:13] forState:UIControlStateDisabled];

[buttonTime setTitle:@"27 feb, 2011 11:10 PM" forState:UIControlStateDisabled];             
[buttonTime setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled];
buttonTime.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:8.0]; 
buttonTime.titleLabel.lineBreakMode= UILineBreakModeWordWrap;
[buttonTime setEnabled:FALSE];
[scrollView addSubview:buttonTime];
[buttonTime release];

Answer

Fury picture Fury · Oct 21, 2014

You can also set the inset values from the Interface Builder Size Inspector inside a Storyboard or xib.

Interface Builder Size Inspector