作者wani420 (wani)
看板MacDev
标题Re: [问题] ToolBar Button 自定图片
时间Thu Aug 2 16:42:55 2012
这个问题我也碰过,
解决的方法应该搜寻的到,
不过大致用sample code讲一下,
1. 先产生一个custom type的UIButton,并设定它的背景图片
UIImage* imageButton = [UIImage imageNamed:@"你的图片.png"];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:imageButton forState:UIControlStateNormal];
[button setFrame:CGRectMake(0, 0, imageButton.size.width, imageButton.size.height)];
[button addTarget:self action:@selector(onclick:) forControlEvents:UIControlEventTouchUpInside];
2. 第二步是关键,产生一个UIBarButtonItem,使用initWithCustomView,并把第一步
产生的UIButton塞进去
UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
接下来就是把这个barButton塞入UIToolBar,这样应该就可以了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.218.106.220