1

如果我的 UIBarButtonItem ( lightButton) 的样式为 Bordered,则以下任一行都会更改背景图像:

[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal style:UIBarButtonItemStyleBordered barMetrics:UIBarMetricsDefault];
[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

如果按钮的样式为普通,则以下行都不会更改背景图像:

[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal style:UIBarButtonItemStylePlain barMetrics:UIBarMetricsDefault];
[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

除了使用之外,是否可以更改普通 UIBarButtonItem 的背景图像initWithCustomView:

4

1 回答 1

2

你可以使用它。

UIButton *modalViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage* imagex = [UIImage imageNamed:@"xxxx.png"];
[modalViewButton addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
[modalViewButton setImage:btnImage forState:UIControlStateNormal];
//modalViewButton setBackImage......
[modalViewButton setFrame:CGRectMake(0, 0, imagex.size.width, imagex.size.height)];
UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:modalViewButton];
于 2012-11-12T03:38:18.797 回答