[英]Setting navigationBar title font of the next view? Help with “setTitleView” to some label?
我试图设置我的navigationBar的标题字体,所以我可以更改字体大小,因为我想要更长的标题...我这样做:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
UILabel *navTitle = [[[UILabel alloc] init] autorelease];
[navTitle sizeToFit];
[navTitle setFont:[UIFont systemFontOfSize:30]];
[navTitle adjustsFontSizeToFitWidth];
[navTitle setBackgroundColor:[UIColor clearColor]];
[navTitle setTextColor:[UIColor whiteColor]];
[navTitle setTextAlignment:UITextAlignmentCenter];
[navTitle setText:@"SuperLongTitleOfMyNaviBar"];
[self.navigationItem setTitleView:navTitle];
}
return self;
}
标题应该为空的地方...有什么建议吗?
非常感谢提前!
在您的代码中,您调用时的sizeToFit
标签没有text
。 因此frame
不会改变。
将text
分配给标签后,应该调用sizeToFit
方法。
您忘记设置标签的框架-更换
UILabel *navTitle = [[[UILabel alloc] init] autorelease];
同
UILabel *navTitle = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 260, 32)] autorelease];
您可以将CGRectMake(0, 0, 260, 32)
替换为您的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.