先前给UINavigation添加图片成功,后来添加标题:
self.title=@"Activity";
没显示任何内容。
我用另一种方法添加标题标签,在第一个视图控制器运行成功,但是在第二个视图控制器修改标题后还是显示先前的标题。
代码:
UIImage *image = [UIImage imageNamed:@"Nav.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar addSubview:imageView];
titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(50,2,250,36)];
titleLabel.text=@"Activity";
titleLabel.textColor=[UIColor whiteColor];
titleLabel.backgroundColor=[UIColor clearColor];
titleLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size :18];
//titleLabel boldSystemFontOfSize:14.0;
[self.navigationController.navigationBar addSubview:titleLabel];
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
[navBar setBackgroundImage:[UIImage imageNamed:@"Nav.png"] forBarMetrics:UIBarMetricsDefault];
}
else
{
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:1];//any tag
if (imageView == nil)
{
imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"Nav.png"]];
[navBar insertSubview:imageView atIndex:0];
[imageView release];
}
}
self.title=@"Activity";
用我的代码试试吧