设置下一个视图的navigationBar标题字体?有关“setTitleView”的帮助到某个标签?
我正在尝试设置导航栏的标题字体,这样我就可以更改字体大小,因为我想要更长的标题...我这样做:
- (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;
}
标题应该为空的地方...有什么建议吗?
预先非常感谢!
I'm trying to set the title font of my navigationBar, so I can change the font size, because I want a longer title... I do it like:
- (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;
}
The place where the title should be is empty... Any suggestions?
Thanks a lot in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的代码中,当您调用
sizeToFit
时,标签没有text
。所以frame
不会改变。在将
text
分配给标签后,您应该调用sizeToFit
方法。In your code, at the time you call
sizeToFit
label has notext
. So theframe
won't get changed.You should be calling
sizeToFit
method after you assign thetext
to the label.您忘记设置标签的框架 - 替换
为
您可以将
CGRectMake(0, 0, 260, 32)
替换为您的值。You forgot to set frame of your label - replace
with
You can replace
CGRectMake(0, 0, 260, 32)
with your values.