开发者

Make a custom title view for a backBarButtonItem

I am making a custom backBarButtonItem with a PNG and that works just fine. The only question is how to change the text color. The way I did that on my navigation bar was this:

CGRect frame 开发者_Python百科= CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aColor.png"]];
self.navigationItem.titleView = label;
label.text = @"aTitle";


dont use autorelease for set label to titleview,after assign them release them

        CGRect frame = CGRectMake(0, 0, 400, 44);

        UILabel *label = [[UILabel alloc] initWithFrame:frame];

        label.backgroundColor = [UIColor clearColor];

        label.font = [UIFont boldSystemFontOfSize:20.0];

        label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];

        label.textAlignment = UITextAlignmentCenter;

        label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aColor.png"]];

        label.text = @"aTitle";

        self.navigationItem.titleView = label;

        [label release];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜