ナビゲーション バーの色を変更しようとしていますが、次の有名なコマンドを使用して実行します。
navController.navigationBar.tintColor = [UIColor colorWithRed:57/255.0 green:50/255.0 blue:36/255.0 alpha:0];
(またはアルファ:1)
問題は、色がグラデーション (上端が白、ボタンが暗い) として表示されることです。この「効果」を取り除き、色を均一にするにはどうすればよいですか?
ナビゲーション バーの色を変更しようとしていますが、次の有名なコマンドを使用して実行します。
navController.navigationBar.tintColor = [UIColor colorWithRed:57/255.0 green:50/255.0 blue:36/255.0 alpha:0];
(またはアルファ:1)
問題は、色がグラデーション (上端が白、ボタンが暗い) として表示されることです。この「効果」を取り除き、色を均一にするにはどうすればよいですか?
サブクラス化したくない場合は、いつでも必要な色で 1x1 の画像を作成し、それをバーの背景画像として設定できます。
UIImage *image = [self imageWithColor:[UIColor redColor]];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
グラデーションを削除するには、選択した色を描画するためにサブクラスUINavigationBar
化して実装する必要があります。drawRect: