添加 UINavigationBar 和 UINavigationItem

卜高超
2023-12-01

UINavigationItem *navItem = [[UINavigationItem alloc] init];

UINavigationBar *navigationbar = [[UINavigationBar alloc] init]; 

navigationbar.items = [NSArray arrayWithObject:navItem];

    

//添加 leftbutton and rightbutton

UIBarButtonItem* backbutton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(back:)];  

UIBarButtonItem* rightbutton = [[UIBarButtonItem alloc] initWithTitle:@"评论" style:UIBarButtonItemStyleDone target:self action:@selector(ShowTalkview:)];

  

[navItem setLeftBarButtonItem:backbutton];

[navItem setRightBarButtonItem:rightbutton];


//添加标题    

navItem.title = @"回复";


//修改UINavigationBar 颜色

navigationbar.tintColor = [UIColor colorWithRed:117/255.0f green:173/255.0f blue:162/255.0f alpha:1];

self.view.backgroundColor = [UIColor colorWithRed:219/255.0f green:235/255.0f blue:223/255.0f alpha:1];

 类似资料: