开发者

how to centre my text label to centre of navigation bar

how to find length of the navigation bar....

i want to display a label centre of the navigation bar programmatically..

so that i can write fo开发者_如何转开发rmula ,so it should work if i rotate my device ...


Use the following code snippet in the viewDidLoad method of UIViewController.

UILabel *label = [[UILabel alloc] init];
label.text = @"Center Label";
label.frame = CGRectMake(0, 0, 100, 30);
label.textAlignment = NSTextAlignmentCenter;
UIBarButtonItem *customButton = [[UIBarButtonItem alloc] initWithCustomView:label];
self.navigationItem.titleView = customButton.customView;

Code is self explanatory. Customize the label and other necessary stuff as required.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜