views:

45

answers:

1

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 formula ,so it should work if i rotate my device ...

A: 

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 = UITextAlignmentCenter;
UIBarButtonItem *customButton = [[UIBarButtonItem alloc] initWithCustomView:label];
self.navigationItem.titleView = customButton.customView;

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

SegFault