uinavigationBar常用設置

設置背景顏色

    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];

設置字體顏色

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

或者

    [self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}];

添加系統自帶的按鈕

   UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"style:UIBarButtonItemStyleDone target:nil action:nil];
   self.navigationItem.rightBarButtonItem = rightButton;

自定義item

    UIButton *servicebtn = [UIButton buttonWithType:UIButtonTypeCustom];
    servicebtn.frame = CGRectMake(0, 0, 30, 30);
    [servicebtn setBackgroundImage:[UIImage imageNamed:@"user"] forState:UIControlStateNormal];
    [servicebtn addTarget:self action:@selector(callService) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:servicebtn];
    self.navigationItem.rightBarButtonItem = item; 



發佈了100 篇原創文章 · 獲贊 216 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章