导航栏加分割线的实现

self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = NO;

self.navigationBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64)];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.tintColor = [UIColor colorWithWhite:1 alpha:0.7];
self.navigationBar.translucent = YES;
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
                                             NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:22]}];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0, self.navigationBar.bounds.size.height - 0.5, self.navigationBar.bounds.size.width, 0.5);
bottomBorder.backgroundColor = [UIColor whiteColor].CGColor;
[self.navigationBar.layer addSublayer:bottomBorder];
[self.view addSubview:self.navigationBar];

UINavigationItem *navigationItem = [[UINavigationItem alloc]initWithTitle:@"Settings"];
[self.navigationBar setItems:@[navigationItem]];

猜你喜欢

转载自eric-gao.iteye.com/blog/2223582