自定义如图工具栏
1 //创建工具栏 2 NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:3]; 3 UIBarButtonItem *confirmBtn = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(confirmPickView)]; 4 UIBarButtonItem *flexibleSpaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 5 6 titleItem = [[UIBarButtonItem alloc] initWithTitle:@"用户类型" style:UIBarButtonItemStylePlain target:nil action:nil]; 7 8 //titleItem.tintColor = [UIColor blackColor]; 9 //titleItem.appearance.tintColor = [UIColor redColor]; 10 11 [titleItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,[UIColor clearColor],UITextAttributeTextShadowColor, nil] forState:UIControlStateNormal]; 12 // 13 // [titleItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,[UIColor clearColor],UITextAttributeTextShadowColor, nil] forState:UIControlStateDisabled]; 14 15 titleItem.enabled = NO; 16 titleItem.tag = 1; 17 18 UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleBordered target:self action:@selector(pickerHide)]; 19 [items addObject:cancelBtn]; 20 [items addObject:flexibleSpaceItem]; 21 [items addObject:titleItem]; 22 [items addObject:flexibleSpaceItem]; 23 [items addObject:confirmBtn]; 24 25 if (toolBar==nil) { 26 toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 44)]; 27 [toolBar setBackgroundImage:[UIImage imageNamed:@"search_buttom"] forToolbarPosition:0 barMetrics:0]; 28 } 29 //toolBar.hidden = YES; 30 31 toolBar.barStyle = UIBarStyleBlackTranslucent; 32 toolBar.items = items; 33 [self.view addSubview:toolBar];