1

含まれているビューの viewDidLoad に次のコードがあります。

// Now add the next button
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(self)];
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
self.navigationItem.rightBarButtonItem = nextButton;

UINavigationController の親は、viewDidLoad にこれを持っています:

[super viewDidLoad];
// Do any additional setup after loading the view.

self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.barTintColor = [UIColor blackColor];

rightBar ボタンをカスタマイズして、背景色やテキストの色を変更するにはどうすればよいですか?

4

4 に答える 4

19

ボタンを割り当てた後、ボタンに tintColor プロパティを設定する必要があります。

self.navigationItem.rightBarButtonItem = nextButton;
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];

それ以外の

self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
self.navigationItem.rightBarButtonItem = nextButton;
于 2014-02-17T11:45:24.660 に答える
5

すべてのバー ボタンを同じ色にしたい場合は、次のコード行を使用できます。

self.window.tintColor = [UIColor redColor];

あなたのアプリデリゲートで。

于 2013-09-30T07:34:36.767 に答える
4

以下のコードを試して、ボタンの色とテキストの色を設定できます

UIView *customBarButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];

UIButton *buttonDone = [UIButton buttonWithType:UIButtonTypeSystem];
[buttonDone addTarget:self action:@selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

buttonDone.backgroundColor = [UIColor redColor];
   // or try this one
// buttonDone.tintColor = [UIColor redColor];

buttonDone.frame = CGRectMake(10, 0, 50, 30);

buttonDone.titleLabel.textColor = [UIColor colorWithRed:141.0/255.0 green:209.0/255.0 blue:205.0/255.0 alpha:1.0];
buttonDone.titleLabel.font = [UIFont fontWithName:@"SourceSansPro-Light" size:20.0f];
[buttonDone setTitle:@"Done" forState:UIControlStateNormal];
[customBarButtonView addSubview:buttonDone];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:customBarButtonView];
于 2014-02-17T12:13:26.713 に答える
1

作業コード..これを試してください。

UIImage *image = [UIImage imageNamed:@"Image.png"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
self.navigationItem.leftBarButtonItem = menuButton;
于 2015-10-23T11:49:56.413 に答える