在自定义UIBarButtonItem周围设置边框 [英] Setting border around custom UIBarButtonItem

查看:167
本文介绍了在自定义UIBarButtonItem周围设置边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将自定义按钮作为导航栏右按钮项。这是代码:

I want to put a custom button as right navigation bar button item. Here is the code:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"my.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(filterResult) forControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(0, 0, 50, 50)];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

问题是我只能看到图像而不是周围的按钮,就像UIBarButtonSystemItemAdd一样或其他类型。

The problem is that I can see only the image and not the button around it like it comes for UIBarButtonSystemItemAdd or other types.

我该怎么办?

推荐答案

[button setImage:[UIImage imageNamed:@"my.png"] forState:UIControlStateNormal];

将整个图像替换为指定状态。您必须绘制完整的图像,而不仅是其上的图标(或所需的任何图像)。

replaces the entire image for the specified state. You have to draw the full own image and not only the icon on it (or whatever you want).

这篇关于在自定义UIBarButtonItem周围设置边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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