Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 更改uinavigationBar多后台iOS 4.3_Objective C_Ios_Uinavigationcontroller_Uinavigationbar - Fatal编程技术网

Objective c 更改uinavigationBar多后台iOS 4.3

Objective c 更改uinavigationBar多后台iOS 4.3,objective-c,ios,uinavigationcontroller,uinavigationbar,Objective C,Ios,Uinavigationcontroller,Uinavigationbar,我曾经使用下面的代码更改UINavigationBar背景: 守则: - (void) drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed:@"NavBar.png"]; [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; } 所以现在我需要不止一个背景NavBar2.png 如何做到这

我曾经使用下面的代码更改UINavigationBar背景:

守则:

    - (void) drawRect:(CGRect)rect
{
    UIImage *image = [UIImage imageNamed:@"NavBar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
所以现在我需要不止一个背景NavBar2.png

如何做到这一点

谢谢

试试这段代码

- (void) drawRect:(CGRect)rect
{
if(navigationBar.tag == 0){
    UIImage *image = [UIImage imageNamed:@"NavBar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
else if(navigationBar.tag == 1)
    UIImage *image = [UIImage imageNamed:@"NavBar1.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
}

R.A.提到的标签逻辑肯定会对你有所帮助

如果您正在iOS5上开发应用程序,那么您还可以查看:

- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

我使用我的原始代码作为图像背景来解决这个问题,然后在导航栏中放置
titleView

UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 165, 44)];
    UIImageView *imgv = [[UIImageView alloc] initWithFrame:aView.frame];
    imgv.image = [UIImage imageNamed:@"NavBar01.png"];
    [aView addSubview:imgv];
    self.navigationController.navigationBar.topItem.titleView =  aView;
    [aView release];
    [imgv release];

您是否为每个导航栏设置了标记并尝试了该操作?@R.a否,我如何在上述方法中获取图像?在XIB中为每个导航栏设置标记,并放置一个if条件以检查navigationBar.tag,并在每个if条件下设置不同的图像