iPhone自定义导航栏编辑按钮

发布于 2024-09-01 01:51:56 字数 716 浏览 2 评论 0原文

我使用以下代码为导航栏按钮使用自定义图像,这允许我制作自定义添加按钮。我希望能够对编辑按钮项目执行相同的操作。

UIImage *image=[UIImage imageNamed:@"Plus.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );    
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];    
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = barButtonItem;
[barButtonItem release];

self.navigationItem.leftBarButtonItem = self.editButtonItem;

我这样做是因为我想更改按钮文本颜色。非常感谢您的帮助,

莎拉

I use custom image for my navigation bar buttons using the following code, that allows me to make custom add button. I want to be able to do the same for the edit button item.

UIImage *image=[UIImage imageNamed:@"Plus.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );    
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];    
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = barButtonItem;
[barButtonItem release];

self.navigationItem.leftBarButtonItem = self.editButtonItem;

I'm doing this because I want to change the button text color.I would appreciate your help,

Sarah

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

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

发布评论

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

评论(1

╰沐子 2024-09-08 01:51:56

您可以像自定义任何其他导航控制按钮一样自定义编辑按钮,例如...

self.editButtonItem.style = UIBarButtonItemStyleBordered;
self.editButtonItem.title = @"Custom";
self.navigationItem.rightBarButtonItem = self.editButtonItem;

不幸的是,更改文本颜色并不像设置“颜色”属性那么容易,因为该属性不存在(同样)这适用于所有导航控制按钮)。但是,可以使用以下帖子中描述的标签...

iPhone 导航栏标题文字颜色

You can customize the edit button in the same way you can customize any other navigation control button, for example...

self.editButtonItem.style = UIBarButtonItemStyleBordered;
self.editButtonItem.title = @"Custom";
self.navigationItem.rightBarButtonItem = self.editButtonItem;

Unfortunately changing the text colour is not as easy as setting a 'color' property, since that property doesn't exist (again this applies to all navigation control buttons). It is however possible using a label as described in the following post...

iPhone Navigation Bar Title text color

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