开发者

Customizing UINavigationBar as in Fox news iPhone app

开发者 https://www.devze.com 2023-01-28 12:00 出处:网络
How can the UINavigationBar customizations be done? Is it using subclassing or categories? I am interested in 2 aspects:

How can the UINavigationBar customizations be done? Is it using subclassing or categories?

Customizing UINavigationBar as in Fox news iPhone app

I am interested in 2 aspects:

  1. Adding an image to the NavBar (like the FOXNEWS logo)
  2. 开发者_JAVA技巧
  3. Customizing the back button to "Shows". (the back button usually takes the title of the previous view in the stack, but there is no title in previous view.)

Thanks in advance for any help


For the Fox News app it looks like they just set the tint color of the navigation bar. As for the Fox News logo, it's probably just an image view on the title view of the navigation bar. This code goes into a view controller's viewDidLoad method:

[self.navigationController.navigationBar setTintColor:/* Custom color here */];

UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
[self.navigationItem setTitleView:logoView];
[logoView release];

To customize the back button you need to place this in the viewDidLoad method of the previous view controller (i.e. the one that this button leads back to):

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Shows"
    style:UIBarButtonItemStyleBordered target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
[backButton release];

If you want to use a totally custom background image for your application's navigation bar, you need to create a custom UINavigationBar category and draw the image within its drawRect: method. Something like this:

@implementation UINavigationBar (UINavigationBarBackgroundImage)

- (void)drawRect:(CGRect)rect
{
    [[UIImage imageNamed:@"navigation-bar"] drawInRect:rect];

    // Optionally you can set the tintColor here to go with the background
}

@end


adding image to navigation bar use this code

- (void)drawRect:(CGRect)rect {

UIColor *color = [UIColor blackColor]; //this use to set button color in FoxNew Site //button color
UIImage *img  = [UIImage imageNamed: @"ImageName"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = color;

}

create category for UINavigationBar

@implementation UINavigationBar (UINavigationBarCategory)
    - (void)drawRect:(CGRect)rect {
     }

@end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号