更新时间:2023-01-28 08:01:01
创建一个 UIButton
并将其用作 UIBarButtonItem
的自定义视图.然后,在按钮的图层上设置backgroundColor
:
Create a UIButton
and use it as the custom view for the UIBarButtonItem
. Then, set the backgroundColor
on the button's layer:
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"Test"];
button.layer.backgroundColor = [UIColor redColor].CGColor;
button.layer.cornerRadius = 4.0;
UIBarButtonItem* buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.toolbarItems = @[buttonItem];