3 回答

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果有人在尋找代碼來(lái)完全復(fù)制一個(gè)簡(jiǎn)單的UIBarButtonItem:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
[button setTitle:@"Delete" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
[button.layer setCornerRadius:4.0f];
[button.layer setMasksToBounds:YES];
[button.layer setBorderWidth:1.0f];
[button.layer setBorderColor: [[UIColor grayColor] CGColor]];
button.frame=CGRectMake(0.0, 100.0, 60.0, 30.0);
[button addTarget:self action:@selector(batchDelete) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* deleteItem = [[UIBarButtonItem alloc] initWithCustomView:button];
和delete.png是:

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以使用所需的外觀創(chuàng)建自定義UIButton,并將其初始化為自定義視圖的UIBarButtonItem。
UIButton *button = [UIButton buttonWithType:....];
...(customize your button)...
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- 3 回答
- 0 關(guān)注
- 464 瀏覽
添加回答
舉報(bào)