Setting border around custom 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) 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).
精彩评论