Thursday, September 3, 2009

A Category on iPhone NavigationBar to set image in background!!!

-(void)setBackgroundImage:(UIImage*)image withTag:(NSInteger)bgTag{
if(image == NULL){ //might be called with NULL argument
return;
}
UIImageView *aTabBarBackground = [[UIImageView alloc]initWithImage:image];
aTabBarBackground
.frame = CGRectMake(0,0,self.frame.size.width,self.frame.size.height);
aTabBarBackground
.tag = bgTag;
[self addSubview:aTabBarBackground];
[self sendSubviewToBack:aTabBarBackground];
[aTabBarBackground release];
}
/* input: The tag you chose to identify the view */
-(void)resetBackground:(NSInteger)bgTag {
[self sendSubviewToBack:[self viewWithTag:bgTag]];
}

After That call the method like:

[navigationControllerForChannels.navigationBar setBackgroundImage:[UIImage imageNamed:@"top_bar.png"] withTag:48151623];

After any Modification to the Bar call:

[self.navigationController.navigationBar resetBackground:48151623];


No comments:

Post a Comment