iphone - iPhone 中的 UINavigationbar 背景

标签 iphone xcode uinavigationbar uinavigationitem

我已将以下代码应用到我的应用程序中以更改导航栏图像。

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
[self setNavigationBarTitle];
}
-(void)setNavigationBarTitle {
UIView *aViewForTitle=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)] autorelease];
UIImageView *aImg=[[UIImageView alloc] initWithFrame:CGRectMake(-8, 0, 320, 45)];
aImg.image=[UIImage imageNamed:@"MyTabBG.png"];
[aViewForTitle addSubview:aImg]; [aImg release]; 
UILabel *lbl=[[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 305, 45)] autorelease];
lbl.backgroundColor=[UIColor clearColor]; lbl.font=[UIFont fontWithName:@"Trebuchet MS" size:22];
lbl.shadowColor=[UIColor blackColor]; [lbl setShadowOffset:CGSizeMake(1,1)];
lbl.textAlignment=UITextAlignmentCenter; lbl.textColor=[UIColor whiteColor]; lbl.text=@"Mobile Tennis Coach Overview";
[aViewForTitle addSubview:lbl];
[self.navigationItem.titleView addSubview:aViewForTitle];
}

请参阅以下图片。你可以看到我面临的问题。

alt text

<小时/> alt text

我的应用程序的每个 View Controller 都有上述方法来设置导航栏背景。

但是,当我将新的 View Controller 推送到我的应用程序时。将出现后退按钮。

我需要显示后退按钮。但图像应该位于后退按钮后面。

现在我有点困惑。

你能帮我解决这个问题吗?

预先感谢您与我分享您的知识。

非常感谢。

最佳答案

经过一个烦人的夜晚后,如果您使用drawLayer,我发现对此有一些细微的调整。使用drawRect,当您播放视频或YouTube视频时,导航栏将被图像替换。我读了一些帖子,说这导致他们的应用程序被拒绝。

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 
{
   if([self isMemberOfClass:[UINavigationBar class]])
   {
     UIImage *image = [UIImage imageNamed:@"navBarBackground.png"];
     CGContextClip(ctx);
     CGContextTranslateCTM(ctx, 0, image.size.height);
     CGContextScaleCTM(ctx, 1.0, -1.0);
     CGContextDrawImage(ctx,
     CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage); 
   }
   else 
   {        
     [super drawLayer:layer inContext:ctx];     
   }
}  
@end

如果这篇文章是准确的,那么使用这种方法一切都应该没问题: http://developer.apple.com/iphone/library/qa/qa2009/qa1637.html

关于iphone - iPhone 中的 UINavigationbar 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1381145/

相关文章:

ios - 无法关闭 CNContactViewController

iOS 13 - 推送时的 Buggy 大标题 UINavigationBar

ios - 状态栏下的 UIViewController 内容

ios - 使用 CAMERA(不是相册)时从 UIImagePickerController 获取缩略图

ios - 在 ios 中使用 Collection View 创建 View

iphone - Xcode 调试和发布之间的区别

c++ - OpenCV 将视频保存到文件

Iphone sdk,如何将数据发布到网络服务器?有人有例子吗?

ios - 如何将委托(delegate)设置为 QLPreviewController 的 UIActivityViewController?

objective-c - iOS:替换数组数组中的对象