原因
最近要做个下拉选项的东东,如:
解决
使用了一个开源控件 BFNavigationBarDrawer
代码很简单:
drawer = [[BFNavigationBarDrawer alloc] init];
//[drawer setBackgroundColor:[UIColor blackColor]];
drawer.scrollView = _tableView;
UIBarButtonItem *area300m = [[UIBarButtonItem alloc] initWithTitle:getText(@"300m") style:UIBarButtonItemStylePlain target:self action:@selector(action:)];
area300m.tag = 300;
[area300m setTintColor:[UIColor whiteColor]];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *area500m = [[UIBarButtonItem alloc] initWithTitle:getText(@"500m") style:UIBarButtonItemStylePlain target:self action:@selector(action:)];
area500m.tag = 500;
[area500m setTintColor:[UIColor whiteColor]];
UIBarButtonItem *area1000m = [[UIBarButtonItem alloc] initWithTitle:getText(@"1000m") style:UIBarButtonItemStylePlain target:self action:@selector(action:)];
area1000m.tag = 1000;
[area1000m setTintColor:[UIColor whiteColor]];
drawer.items = @[area300m, space, area500m, space, area1000m];
代码就不解释了,效果大概是这样的。
效果稍微显得有点不太协调
背景色替换
在 BFNavigationBarDrawer.m 中加入这段代码
-(void)drawRect:(CGRect)rect
{
UIImage *img = [UIImage imageNamed:@"menubk"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
字体颜色替换
[area1000m setTintColor:[UIColor whiteColor]];
最后效果如:
想说的话
我今天是第一次使用uitoolbar,汗