iphone - 设置标签字体

时间:2010-12-19 04:26:36

标签: iphone uibutton label

如何将按钮标签的字体设置为大小为46的Century Gothic Bold。 我正在使用以下代码:

        [self.titleLabel setFont:[UIFont fontWithName:@"Century Gothic-Bold" size:46]];

我的代码是否正确?

3 个答案:

答案 0 :(得分:4)

 UIButton *NameBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    NameBtn=[[UIButton alloc]init];
    [NameBtn setBackgroundColor:[UIColor clearColor]];
    [NameBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    NSString *textb=[[self.searchList objectAtIndex:indexPath.row] objectForKey:@"name"];
    CGSize constraintb = CGSizeMake(310 ,10);
    CGSize sizeb = [textb sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:constraintb lineBreakMode:UILineBreakModeWordWrap];
    [NameBtn setTitle:textb forState:UIControlStateNormal];
    NameBtn.font = [UIFont fontWithName:@"Helvetica-Bold" size: 12.0];
    NameBtn.frame = CGRectMake(85, 12, MAX(sizeb.width ,3.0f),12);
    [NameBtn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    NameBtn.tag=indexPath.row;

    [self.view addSubview:NameBtn];

答案 1 :(得分:2)

我认为iOS不支持你的字体。但是有一种名为AppleGothic的字体。

请参阅此链接

http://www.prepressure.com/fonts/basics/ios-4-fonts

答案 2 :(得分:1)

我昨天用过这个:

onlineButton.titleLabel.font = [UIFont boldSystemFontOfSize:onlineButton.titleLabel.font.pointSize+3];

所以试试这个:

yourButton.titleLabel.font = [UIFont fontWithName:fontName size:size];