How to set the color of `rightBarButtonItem` in the navigation bar?

I want to set the color of the Finish button on the navigation bar as shown below:

enter image description here

Although I set the code as self.doneButton.enabled = NO;, the Finish button is still white. It does not change color like an image.

How to set the code to change the text color of the Finish button, like the Finish button in the image above? Please help me solve this problem. I appreciate your help.

+7
source share
6 answers

to change the color use the barkart

goal c

self.navigationItem.rightBarButtonItem = yourRightbarbuttonName;
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor]; // add your color

Swift

or set on a bulletin board Set the color of the bat button

self.navigationItem.rightBarButtonItem = yourRightbarbuttonName
self.navigationItem.rightBarButtonItem.tintColor = UIColor.blueColor()

,

C

self.navigationItem.rightBarButtonItem.enabled = YES;

Swift

self.navigationItem.rightBarButtonItem.enabled = true

,

C

self.navigationItem.rightBarButtonItem.enabled = NO;

Swift

self.navigationItem.rightBarButtonItem.enabled = false
+6

( )

self.navigationItem.rightBarButtonItem.tintColor = [UIColor lightGrayColor];
+1

XIB/Storyboard, Set panel button color

- tintColor barbutton.

+1

UIBarButtonItem *rightBarButton=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(editProfileClick)];
rightBarButton.tintColor=[UIColor whiteColor];
self.navigationItem.rightBarButtonItem = rightBarButton;


-(void)editProfileClick
{
//your methods
}
+1

, , . , , "" . .

-, ​​ :

- (void)changeStatusOfRightBarButton:(BOOL)enabled withColorAlpha:(CGFloat)numberAlpha {
    _doneButton.enabled = enabled;
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
    setTitleTextAttributes:
    @{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"FFFFFF" alpha:numberAlpha],
    NSFontAttributeName:[UIFont fontAvenirNextRegularWithSize:15.0f]
    }
    forState:UIControlStateNormal];

}

, -, viewDidload :

if (self.noteTextView.text.length == 0) {
    [self.noteTextView becomeFirstResponder];
    [self changeStatusOfRightBarButton:NO withColorAlpha:0.44f];

}

, "" .

0

To update the text color of an element in the right panel, we must use "setTitleTextAttributes" (swift 5). Please try this:

let rightBarButton = UIBarButtonItem(title: "your text", style: .plain, target: nil, action: nil)
rightBarButton.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.black], for: .normal)
navigationItem.rightBarButtonItem = rightBarButton
0
source

Source: https://habr.com/ru/post/1650752/


All Articles