Разделение на подклассы UINavigationBar …, как я использую его в UINavigationController?

Я хотел разделить UINavigationBar на подклассы (для установки пользовательского фонового изображения и цвета текста) и использование это для всех панелей навигации в моем приложении. Смотря на документы API для UINavigationController, похоже, что navigationBar только для чтения:

@property (неатомарный, только для чтения) UINavigationBar *navigationBar

Существует ли способ на самом деле использовать пользовательский UINavigationBar в моем UIViewControllers? Я знаю, что другие приложения сделали пользовательские панели навигации, как flickr:

http://img.skitch.com/20100520-bpxjaca11h5xne5yakjdc2m6xx.png

Вот мой подкласс UINavigationBar:

#import 

@interface MyNavigationBar : UINavigationBar  {

}

@end

реализация

#import "MyNavigationBar.h"

@implementation MyNavigationBar

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    // override the standard background with our own custom one
    UIImage *image = [[UIImage imageNamed:@"navigation_bar_bgd.png"] retain];
    [image drawInRect:rect];
    [image release];
}

#pragma mark -
#pragma mark UINavigationDelegate Methods

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    // use the title of the passed in view controller
    NSString *title = [viewController title];

    // create our own UILabel with custom color, text, etc
    UILabel *titleView = [[UILabel alloc] init];
    [titleView setFont:[UIFont boldSystemFontOfSize:18]];
    [titleView setTextColor:[UIColor blackColor]];
    titleView.text = title;
    titleView.backgroundColor = [UIColor clearColor];
    [titleView sizeToFit];

    viewController.navigationItem.titleView = titleView;
    [titleView release];

    viewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:0.8];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
}


- (void)dealloc {
    [super dealloc];
}

@end

Я знаю, что могу использовать категорию для изменения фонового изображения, но я все еще хочу смочь установить цвет текста заголовка панели навигации

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"navigation_bar_bgd.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

какие-либо предложения или другие решения? Я в основном хочу создать светлый фон и темный текст как панели навигации приложения Flickr

8
задан funkadelic 20 May 2010 в 23:42
поделиться

2 ответа

Установите для свойства UINavigationBar "оттенок" нужный цвет.

2
ответ дан 5 December 2019 в 20:14
поделиться

Попробуйте создать изображение [UIColor colorWithPatternImage: (UIImage *)] и установить для него свойство backgroundColor элемента NavBar. Еще не пробовал, но сделаю прямо сейчас.

2
ответ дан 5 December 2019 в 20:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: