如何复制后退按钮?

发布于 2024-11-05 07:19:10 字数 194 浏览 8 评论 0原文

我知道更改后退按钮文本颜色的唯一方法是制作自己的自定义按钮:

self.navigationItem.backBarButtonItem = yourCustomBackButton;

我的问题是:如何创建一个后退按钮,该按钮考虑色调颜色并且看起来与默认值完全相同后退按钮除了文本的颜色(除非它是白色的)?

I understand that the only way to change the color of the text of the back button is to make your own custom button:

self.navigationItem.backBarButtonItem = yourCustomBackButton;

My question is: How do I create a back button that takes tint color into account and looks exactly the same as the default back button except for the color of the text (unless it's white)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走就滚别墨迹 2024-11-12 07:19:10

将类别添加到 UINavigationBar 并在那里设置其背景颜色。此代码还展示了如何使用图像。

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {

/***
 // use a custom color
 UIColor *color = [UIColor colorWithRed:.455 green:.365 blue:0 alpha:.9];
 3    CGContextRef context = UIGraphicsGetCurrentContext();
 4    CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
 5    CGContextFillRect(context, rect);
 6    self.tintColor = color;
 ***/

// use a custom background image
UIImage *img  = [UIImage imageNamed: [PlistVariables sharedInstance].navbarBackgroundImageName ];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [PlistVariables sharedInstance].navbarTintColor;
 }

以下是使用 RGB 192,93,0 作为背景棕色的一些示例输出:

在此处输入图像描述

Add a category to the UINavigationBar and set it's background color there. This code also shows how to use an image.

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {

/***
 // use a custom color
 UIColor *color = [UIColor colorWithRed:.455 green:.365 blue:0 alpha:.9];
 3    CGContextRef context = UIGraphicsGetCurrentContext();
 4    CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
 5    CGContextFillRect(context, rect);
 6    self.tintColor = color;
 ***/

// use a custom background image
UIImage *img  = [UIImage imageNamed: [PlistVariables sharedInstance].navbarBackgroundImageName ];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [PlistVariables sharedInstance].navbarTintColor;
 }

Here's some sample output using RGB 192,93,0 for background brown:

enter image description here

动听の歌 2024-11-12 07:19:10

确实无法更改后退按钮的文本颜色。但是,您可以将自定义视图分配给 leftBarButtonItem 属性。我整理了一个简单的小项目,展示了如何重新创建标准 iOS UI 的输入/输出动画。需要一些技巧,但您应该能够将带有标签的按钮分配给自定义视图并更新它。

https://github.com/typeoneerror/BBCustomBackButtonViewController

It's really not possible to change the text color of the back button. You can however assign a custom view to the leftBarButtonItem property. I've put together a simple little project showing how to do that that recreates the in/out animation of the standard iOS UI. Takes a bit of hacking, but you should be able to assign a button with a label in it to the custom view and update that.

https://github.com/typeoneerror/BBCustomBackButtonViewController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文