开发者

Setting border around custom UIBarButtonItem

开发者 https://www.devze.com 2023-02-11 02:22 出处:网络
I want to put a custom button as right navigation bar button item. Here is the code: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

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) fo开发者_JS百科rControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(0, 0, 50, 50)];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

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

What should I do?


[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).

0

精彩评论

暂无评论...
验证码 换一张
取 消