开发者

How to set custom view for UIBarButtonItem?

开发者 https://www.devze.com 2023-01-08 18:02 出处:网络
I am trying to put a label in a UIBarButtonItem. Here is my viewDidLoad method: characterCountLabel = [[UILabel alloc] init];

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

精彩评论

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