更改UINavigationBar标题的内部阴影的颜色

时间:2011-07-20 13:11:40

标签: ios uinavigationbar

UINavigationBar标题的默认内部阴影为黑色。

我可以更改此颜色吗?

1 个答案:

答案 0 :(得分:2)

我的方法是继承UINavigationItem并操纵标题的setter,以便它创建一个titleView作为UILabel,可以随意配置。

-(void)awakeFromNib{
    if(self.title){
        [self setTitle:self.title];
    }
}

-(id)initWithTitle:(NSString *)title{
    self = [super init];
    if(self){
        [self setTitle:title];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    [super setTitle:title];
    UILabel* label = [[[UILabel alloc] init] autorelease];
    label.text = title;
    label.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    label.shadowColor = [UIColor lightGrayColor];
    label.shadowOffset = CGSizeMake(0, -1);
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor blackColor];
    label.backgroundColor = [UIColor clearColor];
    [label sizeToFit];
    self.titleView = label;

}