我以编程方式创建了一个工具栏:
UIToolbar *boolbar = [UIToolbar new];
boolbar.barStyle = UIBarStyleDefault;
boolbar.tintColor = [UIColor orangeColor];
[boolbar sizeToFit];
然后给它加了一个按钮:
UIBarButtonItem *cancelleftBarButton =[[UIBarButtonItem alloc]initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(tapBackGround:)];
cancelleftBarButton.tintColor = [UIColor orangeColor];
NSArray *array = [NSArray arrayWithObjects:cancelleftBarButton, nil];
[boolbar setItems:array animated:YES];
但是,此按钮仅出现在工具栏的左侧。是否可以将其放在工具栏的右侧?