6

Possible Duplicate:
UIButton title and image alignment query

I need to implement UIButton show in below image

please help me how to implement

Thanks, Prasad

enter image description here

Community
  • 1
  • 1
Prasad
  • 1,904
  • 4
  • 19
  • 24

3 Answers3

14

Have a look to the titleEdgeInsets property of UIButton.

@property(nonatomic) UIEdgeInsets titleEdgeInsets

Use the below approach to get both with the UIButton .

[myButton setImage: [UIImage imageNamed:@"settingImage.png"] forState:UIControlStateNormal];
[myButton setTitleEdgeInsets:UIEdgeInsetsMake(100.0, -100.0, 10.0, 15.0)];
[myButton setTitle:@"settings" forState:UIControlStateNormal];
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
0

Take Outlets Of Buttons.

UIImageView *img1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blue-thumb.jpg"]];
    CGRect rect1=CGRectMake(0,0,20,30);
    [img1 setFrame:rect1];
    [btn1 addSubview:img1];

You also can set Label with it.

Arpit B Parekh
  • 1,932
  • 5
  • 36
  • 57
0

the easiest I find is to just make a png file that has the width of (left image + text width + left image), but only contains the left settings image.

Then use this as background of your button.

The text comes from the button itself, so you may easily change the text without having to change the image. If you now center the text it will look perfect with the image on the left and the text next to it.

The code would look like:

  1. [myBtn setTitle: @"settings" forState:UIControlStateNormal]
  2. [myBtn setBackgroundImage: [UIImage imageNamed:@"myBtn.png"] forState:UIControlStateNormal];

Also it will be compatible with localization in case you ever plan to have it in a different langauge.

user387184
  • 10,953
  • 12
  • 77
  • 147