如果我的UIBarButtonItem(lightButton
)具有Bordered样式,则以下任一行都会更改背景图像:
[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal style:UIBarButtonItemStyleBordered barMetrics:UIBarMetricsDefault];
[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
如果按钮的样式为Plain,则以下两行均不会更改背景图像:
[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal style:UIBarButtonItemStylePlain barMetrics:UIBarMetricsDefault];
[lightButton setBackgroundImage:resizeableImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
除了使用initWithCustomView:
之外,是否可以更改Plain UIBarButtonItem的背景图像?
答案 0 :(得分: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];