Setting border around custom UIBarButtonItem

ⅰ亾dé卋堺 提交于 2020-01-15 09:16:07

问题


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];

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?


回答1:


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



来源:https://stackoverflow.com/questions/5020267/setting-border-around-custom-uibarbuttonitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!