[英]Customize UIBarButtonItem with uitoolbar
我正在尝试创建一个完全自定义的UIToolbar
,其中包含2个完全自定义的按钮。 每个按钮的宽度应为工具栏宽度的50%。
@property (weak, nonatomic) IBOutlet UIToolbar *ToolBar;
-(void)viewDidLoad
{
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(0, 0, self.ToolBar.frame.size.width/2-10,self.ToolBar.frame.size.height-2);
button.layer.borderColor=[UIColor blueColor].CGColor;
button.layer.borderWidth=1.0f;
[button setTitle:@"Message" forState:UIControlStateNormal];
button.titleLabel.font=[UIFont boldSystemFontOfSize:14];
UIBarButtonItem *MsgButton =[[UIBarButtonItem alloc]initWithCustomView:button];
[MsgButton setTitle:@"Msg"];
UIButton *button2 =[UIButton buttonWithType:UIButtonTypeCustom];
button2.frame=CGRectMake(0, 0, self.ToolBar.frame.size.width/2-10,self.ToolBar.frame.size.height-2);
button2.layer.borderColor=[UIColor redColor].CGColor;
button2.layer.borderWidth=1.0f;
[button2 setTitle:@"Message" forState:UIControlStateNormal];
button2.titleLabel.font=[UIFont boldSystemFontOfSize:14];
UIBarButtonItem *RelationButton =[[UIBarButtonItem alloc]initWithCustomView:button2];
self.ToolBar.items=@[MsgButton,RelationButton];
}
屏幕截图显示了它现在在我的PC上的屏幕截图。
这里是问题:
尝试这个
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(-15, 0, self.ToolBar.frame.size.width/2-20,self.ToolBar.frame.size.height-2);
button.layer.borderColor=[UIColor blueColor].CGColor;
button.layer.borderWidth=1.0f;
[button setTitle:@"Message" forState:UIControlStateNormal];
button.titleLabel.font=[UIFont boldSystemFontOfSize:14];
UIButton *button2 =[UIButton buttonWithType:UIButtonTypeCustom];
button2.frame=CGRectMake(self.ToolBar.frame.size.width/2-35, 0, self.ToolBar.frame.size.width/2-20,self.ToolBar.frame.size.height-2);
button2.layer.borderColor=[UIColor redColor].CGColor;
button2.layer.borderWidth=1.0f;
[button2 setTitle:@"Message" forState:UIControlStateNormal];
button2.titleLabel.font=[UIFont boldSystemFontOfSize:14];
UIView *barView = [[UIView alloc] init];
barView.frame = self.ToolBar.frame ;
[barView addSubview:button];
[barView addSubview:button2];
UIBarButtonItem *RelationButton =[[UIBarButtonItem alloc]initWithCustomView:barView];
self.ToolBar.items=@[RelationButton];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.