navigation
- - (void)renderNv
- {
- UIImage *backgroundImage = [UIImage imageNamed:@"nv.png"]; //获取图片
- CGRect rt = self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 64);
- backgroundImage = [self scaleToSize:backgroundImage rt:rt];//设置图片的大小与Navigation Bar相同
- [self.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; //设置背景
- //设置背景样式可用通过设置tintColor来设置
- self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:50/255.0 green:138/255.0 blue:233/255.0 alpha:1.0];//改变navigation的背景颜色
- [self setNVBtn:@"nvLeftBtn.png"];
- [_leftBtn addTarget:self action:@selector(showEnergy) forControlEvents:UIControlEventTouchUpInside];
- [self setRightBtn];
- }
- - (UIImage *)scaleToSize:(UIImage *)img rt:(CGRect)rt
- {
- UIGraphicsBeginImageContext(CGSizeMake(rt.size.width, rt.size.height) );
- [img drawInRect:rt];
- UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return scaledImage;
- }
left button
- - (void)setNVBtn:(NSString*) imName
- {
- _leftBtn.frame=CGRectMake(0, 0, 30, 30);
- [_leftBtn setBackgroundImage:[UIImage imageNamed:imName] forState:UIControlStateNormal];
- self.navigationItem.leftBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView: _leftBtn];
- }