简体   繁体   中英

change UINavigationItem titleView text

I'm using custom titleView for navigation bar in viewDidLoad, here is my code:

UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 220, 44)];
titleView.text = @"Hello";
titleView.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = titleView;

But I want to change this title text later programmatically, I tried couple ways with no success.

self.navigationItem.titleView.text = @"Loading...";
self.navigationItem.title = @"Loading...";

How do I change the title text in custom titleView ?

If the initial code works you should allocate a new label, set its text and reset it and that should probably work.

Alternatively store the label as a property and try setting its title from self.label.text = @"..."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM