【发布时间】:2011-09-03 07:22:13
【问题描述】:
我需要一个UIButton 来显示两行文本,其中第一行用作标题,第二行用作某种副标题,因此它应该具有较小的字体大小。
现在我的按钮有两行,自定义字体,标题/副标题的内容分别来自UILabel。
UIFont *displayFont = [UIFont fontWithName:@"Chalkboard" size:15];
NSString *buttonLabel;
UILabel *headline = [[UILabel alloc] init];
headline.text = @"This is the title";
UILabel *subtitle = [[UILabel alloc] init];
subtitle.text = @"this is the sub";
buttonLabel = [NSString stringWithFormat:@"%@\n%@", headline.text, subtitle.text];
[openDetail.titleLabel setLineBreakMode:UILineBreakModeWordWrap];
[openDetail setTitle:buttonLabel forState:UIControlStateNormal];
[openDetail.titleLabel setTextAlignment:UITextAlignmentCenter];
openDetail.titleLabel.font = displayFont;
我尝试将标签本身设置为displayFont,这样我就可以制作第二个UIFont,作为它的副标题。不幸的是,按钮标签不会是这种字体,如果我保持上面显示的其余部分,但会切换回 Arial,我认为是,并且根本没有改变字体大小。
知道如何在第二行中实现更小的字体吗?
字体的附带问题:我将 Chalkboard.ttc 添加到我的资源中,并将其添加为我的 info.plist 中的条目作为“应用程序提供的字体”。不过,如果我尝试在 IB 中设置字体,我会显示另一种字体(非常类似于 Helvetica)。我现在真的必须以编程方式设置每个按钮的字体吗?
【问题讨论】:
标签: iphone objective-c uibutton font-size line-breaks