1

I want to create a UIBarButtonItem which has an icon on the left and text on the right. Any hints how to do this?

thanks.

pseudonym_127
  • 357
  • 7
  • 16
  • check this other [question](http://stackoverflow.com/questions/3903018/how-to-have-a-uibarbuttonitem-with-both-image-and-text) – tkanzakic Jan 15 '13 at 09:25
  • please look at my post below – pseudonym_127 Jan 15 '13 at 10:14
  • once that you have a Custom Button then check this other [question](http://stackoverflow.com/questions/4564621/aligning-text-and-image-on-uibutton-with-imageedgeinsets-and-titleedgeinsets) to see how align the text and the image – tkanzakic Jan 15 '13 at 10:18

1 Answers1

-1

Aligning text and image on UIButton to configure this with contentEdgeInset, imageEdgeInsets and titleEdgeInsets have a look at this Aligning text and image on UIButton with imageEdgeInsets and titleEdgeInsets

    UIImage *img = [UIImage imageNamed:@"08-chat.png"];

    UIButton *customBarBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [customBarBtn setBackgroundImage:chatImage forState:UIControlStateNormal];
    [customBarBtn setTitle:@"Chat" forState:UIControlStateNormal];
    customBarBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, spacing);
    customBarBtn.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
    customBarBtn.frame = (CGRect) {
        .size.width = 100,
        .size.height = 30,
    };

    UIBarButtonItem *barButton= [[[UIBarButtonItem alloc] initWithCustomView:customBarBtn] autorelease];
Community
  • 1
  • 1
laxonline
  • 2,657
  • 1
  • 20
  • 37
  • Actually this is now quite what I want but thanks anyway. I need an image on the left and text on the right, this however, adds the image as a background (I hope to resolve this myself). But another problem is that the type of button that is added, seems kind of "plain". I would like a button that looks like this button (on the right): http://postimage.org/image/yk8oqt3mf/, what I get is button which is on the left, without rounded borders and gradient background. I would appreciate any further help on this!. – pseudonym_127 Jan 15 '13 at 10:08
  • Thanks. Does it also resolve the issue I mentioned? (i.e., in the attached image on the web link?). That now this custom button does not have rounded borders and gradient background as I attached on this image? http://postimage.org/image/yk8oqt3mf/ – pseudonym_127 Jan 15 '13 at 10:58