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
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
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];
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.
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:
[myBtn setTitle: @"settings" forState:UIControlStateNormal]
[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.