像 Apple 的 iPad 邮件应用程序一样显示 UIBarButtonItem [英] Show UIBarButtonItem just like Apple's iPad Mail App

查看:50
本文介绍了像 Apple 的 iPad 邮件应用程序一样显示 UIBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple 的 iPad Mail 应用有几个图标嵌入显示在 navigationItemsetRightBarButtonItems 区域中.拆分视图控制器的详细视图:

Apple's iPad Mail app has a few icons that appear embedded in the setRightBarButtonItems area of the navigationItem of the detail view of the split view controller:

如何将图标添加到这样的导航项栏中(我已经有了图标).

How can I add icons to the navigationItem bar like this (I have the icons already).

我的问题是 UIBarButtonItem 类引用似乎没有合适的 UIBarButtonItemStyle 允许按钮周围没有边框.我已经尝试通过 initWithCustomView 配置 UIBarButtonItem 但点击按钮不起作用.

My issue is that the UIBarButtonItem class reference doesn't seem to have an appropriate UIBarButtonItemStyle that allows for no border around the button. I've tried configuring the UIBarButtonItem via initWithCustomView yet tapping the button doesn't work.

预先感谢您的任何建议

干杯

我可以使用 UIBarButtonItemStylePlain 但它看起来不像苹果按钮那样嵌入",这是我追求的外观.

I could use UIBarButtonItemStylePlain however it doesn't look 'embedded' like the apple buttons, which is the look I am after.

推荐答案

我已经解决了,可以产生以下结果:

I've worked it out and can produce the following result:

这是我使用的代码.它可以进行优化,但是出于演示目的很好且重复:

Here is the code I use. It could be optimised however is nice and repetitive for demonstration purposes:

- (void)setupNavigationItemButtons {

float buttonWidth = 60;
float buttonHeight = 40;

UIImage *imageA = [UIImage imageNamed:@"212-action2.png"]; 
UIImage *imageB = [UIImage imageNamed:@"111-user.png"];
UIImage *imageC = [UIImage imageNamed:@"122-stats.png"];

UIButton *buttonA = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, buttonHeight)];
UIButton *buttonB = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, buttonHeight)];
UIButton *buttonC = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, buttonHeight)];

[buttonA addTarget:self action:@selector(doSomething:)      forControlEvents:UIControlEventTouchUpInside];
[buttonB addTarget:self action:@selector(doSomethingElse:)  forControlEvents:UIControlEventTouchUpInside];
[buttonC addTarget:self action:@selector(doSomethingRandom:)forControlEvents:UIControlEventTouchUpInside];

[buttonA setImage:imageA forState:UIControlStateNormal];
[buttonB setImage:imageB forState:UIControlStateNormal];
[buttonC setImage:imageC forState:UIControlStateNormal];

UIBarButtonItem *buttonItemA = [[UIBarButtonItem alloc] initWithCustomView:buttonA];
UIBarButtonItem *buttonItemB = [[UIBarButtonItem alloc] initWithCustomView:buttonB];
UIBarButtonItem *buttonItemC = [[UIBarButtonItem alloc] initWithCustomView:buttonC];

[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:buttonItemA, buttonItemB, buttonItemC,nil]];

}

这篇关于像 Apple 的 iPad 邮件应用程序一样显示 UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆