putting labels, buttons on the navigation bar iOS

前端 未结 5 1681
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 11:59

I have created custom navigation controller,

I want to be added, a date at the left, a back button on the right and the title next to back button.

I tried to

5条回答
  •  执念已碎
    2021-01-13 12:38

    You need to change the titleView of the topItem. Like this:

    naviBarObj.topItem.titleView = navLabel;
    

    ** update: Complete code (tested and working) **

    UINavigationBar *naviBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(.0, .0, 320.0, 44.0)];
    UINavigationItem *navItem = [[UINavigationItem alloc] init];
    navItem.titleView = titleLbl;
    
    [naviBar pushNavigationItem: navItem animated: NO];
    [navItem release]; // you don't need this for ARC
    
    [self.view addSubview: naviBar];
    [naviBar release]; // you don't need this for ARC
    

提交回复
热议问题