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.
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.
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];