UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[leftBtn setTitleColor:lightBlue forState:UIControlStateNormal];
leftBtn.backgroundColor = [UIColor clearColor];
leftBtn.frame = CGRectMake(0, 0, 60, 44);
[leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
UIImageView *backImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 12, 12, 20)];
backImage.image = [UIImage imageNamed:@"back"];
[leftBtn addSubview:backImage];
UILabel* middleLabel = [[UILabel alloc]init];
middleLabel.textColor = [UIColor whiteColor];
middleLabel.frame = CGRectMake(0, 0, 120, 44);
middleLabel.textAlignment = NSTextAlignmentCenter;
middleLabel.font = [UIFont boldSystemFontOfSize:24.0];
middleLabel.backgroundColor = [UIColor clearColor];
middleLabel.text = @"XXXX";
UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
self.navigationItem.leftBarButtonItem = left;
self.navigationItem.titleView = middleLabel;
if (version<7.0) {
self.navigationController.navigationBar.tintColor = lightBlue;
} else {
self.navigationController.navigationBar.barTintColor = lightBlue;
self.navigationController.navigationBar.translucent = NO;
}
原文地址:http://blog.csdn.net/zh_2608/article/details/41750373