给self.navigationItem.rightBarButtonItem设置字体颜色所引发的忧伤

其实一般去自定义一个 UIBarButtonItem 然后都会玩得很 high,很满足,但是孤独一生的我每次都是想法设法不去自定义,实在是 simple,但是毕竟也是好久没有搞iOS了,刚刚,想给 self.navigationItem.rightBarButtonItem 设置一下字体颜色:

UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithTitle:@"切换账户" style:(UIBarButtonItemStyleDone) target:self action:@selector(moreConfig:)];
self.navigationItem.rightBarButtonItem = rightitem;
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor redColor]];
//self.navigationItem.rightBarButtonItem.tintColor = [UIColor redColor];

嗯嗯没错,没有成功,但是看到别人有说成功的,我也是蛮纠结的,但也没有搞明白,所以想还是试下多属性文本样式来搞搞,当然这个是成功的:

UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithTitle:@"切换账户" style:(UIBarButtonItemStyleDone) target:self action:@selector(moreConfig:)];
NSDictionary *dic = [NSDictionary dictionaryWithObject:DRGBCOLOR(44, 163, 255, 1) forKey:NSForegroundColorAttributeName];
[rightitem setTitleTextAttributes:dic forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = rightitem;

你可能感兴趣的:(给self.navigationItem.rightBarButtonItem设置字体颜色所引发的忧伤)