开发者

How to set custom view for UIBarButtonItem?

I am trying to put a label in a UIBarButtonItem. Here is my viewDidLoad method:

characterCountLabel = [[UILabel alloc] init];
characterCountLabel.text = @"HELLO";
charCountButton = [[UIBarButtonItem alloc]initWithCustomView:characterCountLabel];

Everything is hooked up properly in IB. Why is the label n开发者_运维百科ot appearing inside of my UIBarButtonItem?


A couple things come to mind. First, your label has no frame. Try using

characterCountLabel = [[UILabel alloc] initWithFrame:
                                 CGRectMake(0.0f, 0.0, 200.0f, 25.0f)];

Next, can you show us the code where you actually add the bar button item? What are you adding it to--a navigation bar or a toolbar?

When you say everything is hooked up in IB, what are you referring to? The toolbar? Navigation bar? Are you using a navigation controller? If not, then you should be able to just add an item to a navigation bar in IB.

A little more information would help us help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜