Apple的iPad 邮件应用程序在 navigationItem 的 setRightBarButtonItems 区域中显示了一些 embedded 的图标拆分视图控制器的详细视图:
如何将这样的图标添加到navigationItem栏(我已经有了图标)。
我的问题是UIBarButtonItem类引用似乎没有适当的UIBarButtonItemStyle,它允许按钮周围没有边框。我已经尝试通过initWithCustomView配置UIBarButtonItem但是点击该按钮不起作用。
提前感谢任何建议
干杯
编辑:我可以使用UIBarButtonItemStylePlain,但它看起来不像苹果按钮那样“嵌入”,这就是我追求的外观。
答案 0 :(得分:0)
我已经解决了,可以产生以下结果:
这是我使用的代码。它可以进行优化,但是为了演示目的,它是好的和重复的:
- (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]];
}