Re: [問題] ToolBar Button 自定圖片
這個問題我也碰過,
解決的方法應該搜尋的到,
不過大致用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
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):