Nar*_*lle 2 iphone objective-c line-breaks font-size uibutton
我需要一个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;
Run Code Online (Sandbox Code Playgroud)
我试图将标签本身设置为displayFont,所以我可以制作第二个UIFont,制作它的副标题.不幸的是,按钮标签将不是这种字体,如果我保持其余如上所示,但将切换回Arial,我认为它是,并且根本没有改变字体大小.
知道如何在第二行中实现更小的字体大小吗?
字体的问题:我将Chalkboard.ttc添加到我的资源中,并将其作为我的info.plist中的条目添加为"应用程序提供的字体".不过,如果我尝试在IB中设置字体,我将显示另一种字体(非常类似于Helvetica).我现在必须以编程方式设置每个按钮字体吗?
小智 5
试试这个
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(20 , 13, 200, 85)];
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(8, 8, 185, 30)];
[title setBackgroundColor:[UIColor clearColor]];
[title setFont:[UIFont fontWithName:@"Chalkboard" size:14]];
[title setFont:[UIFont boldSystemFontOfSize:18]];
title.text=@"This is the title";
[title setTextColor:[UIColor blackColor]];
[btn addSubview:title];
UILabel *subtitle = [[UILabel alloc]initWithFrame:CGRectMake(8, 20, 185, 30)];
[subtitle setBackgroundColor:[UIColor clearColor]];
[subtitle setFont:[UIFont fontWithName:@"Helvetica" size:14]];
subtitle.text=@"This is the sub";
[subtitle setTextColor:[UIColor blackColor]];
[btn addSubview:subtitle];
[title release];
[subtitle release];
[self.view addSubview:btn];
Run Code Online (Sandbox Code Playgroud)