Reputation: 864
I need to change the font for my UIBarButtonItem title. Currently it is, barbuttonItem.customView = customLabel
. And now I wish to add a selector and target, so that I can get the touchDown event. With the same font style.
thanks in advance,
Upvotes: 2
Views: 5308
Reputation: 11284
If you don't want to create a custom view you can use the setTitleTextAttributes method on the UIBarItem to set the font. For example here is a UIBarButtonItem using this to manipulate the font:
[self.filterButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica Neue" size:15.0],UITextAttributeFont,
nil]forState:UIControlStateNormal];
Upvotes: 6
Reputation: 2006
You should just use a UIButton as your custom view.
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
customButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
[customButton setImage:[UIImage imageNamed:@"image_up_state.png"] forState:UIControlStateNormal];
[customButton setImage: [UIImage imageNamed:@"image_down_state.png"] forState:UIControlStateHighlighted];
[customButton addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
This will set your custom font and then allow you to have an up state image and down state image. When you tap the button, it will call the doSomething message.
Upvotes: 4