Can set background image for UIBarButtonItem in nav bar, but not bottom toolbar

房东的猫 提交于 2019-12-07 08:19:26

You should try the following method to do the same.

Setting custom view in UIBarButtonItem.

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 30, 30);
[btn setImage:[UIImage imageNamed:@"someImage.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(resetCriteria:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *Item = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.toolbarItems   = [NSArray arrayWithObject:Item];
[Item release];

We can set any view in UIBarButtonItem with CustomView init method. We could set the ImageView. But ImageView doesnot handle UIControl Events.

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