- 效果展示
- 代码示例
#import "ViewController.h"
@interface ViewController ()
@property(strong, nonatomic) UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat toolbarHeight = 44;
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, screen.size.height - toolbarHeight, screen.size.width, toolbarHeight)];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)];
UIBarButtonItem *openButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"open" style:UIBarButtonItemStylePlain target:self action:@selector(open:)];
UIBarButtonItem *flexibleButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
toolbar.items = @[saveButton,flexibleButton,openButtonItem];
[self.view addSubview:toolbar];
CGFloat labelWidth = 84;
CGFloat labelHeight = 21;
CGFloat labelTopView = 250;
self.label = [[UILabel alloc] initWithFrame:CGRectMake((screen.size.width - labelWidth) / 2, labelTopView, labelWidth, labelHeight)];
self.label.text = @"label";
self.label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview: _label];
}
-(void) save:(id)sender {
self.label.text = @"点击save";
}
-(void)open: (id)sender {
_label.text = @"点击open";
}
@end