读书人

UILabel施用自定义字体

发布时间: 2012-07-05 07:59:17 作者: rapoo

UILabel使用自定义字体

xcode 4

?

下载自定义字体(例如:Blazed.ttf)后,拖入项目当中。

?

在 Supporting Files 中找到 (项目名称)-info.plist, 添加 Fonts provided by application 项, 打开对应的数组,可以设置多个字体,在Item0中 输入Blazed.ttf。

?

在程序中通过字体family name,找出字体名字。然后使用

?

label.font = [UIFont fontwithname:@"Blazed" size:42];

??或者

?

UIFont *tfont = [UIFont fontWithName:@"Blazed" size:42];label.font = tfont;
??

例外还有其他设置:

?

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];     
??
//设置阴影[label setShadowColor:[UIColor blackColor]];[label setShadowOffset:CGSizeMake(-2, 3)];//设置是否能与用户进行交互     label.userInteractionEnabled = YES;      //设置label中的文字是否可变,默认值是YES     label.enabled = NO;  //设置高亮     label.highlighted = YES;     label.highlightedTextColor = [UIColor orangeColor];   //设置label的行数     label.numberOfLines = 2;    //设置文字位置     label.textAlignment = UITextAlignmentRight;     label.textAlignment = UITextAlignmentCenter;     //设置字体大小适应label宽度     label.adjustsFontSizeToFitWidth = YES; //设置字体:粗体,正常的是 SystemFontOfSize     label.font = [UIFont boldSystemFontOfSize:20]; //设置显示文字     label.text = @"This is my label !";   //设置文字过长时的显示格式     label.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间     //  typedef enum {     //      UILineBreakModeWordWrap = 0,     //      UILineBreakModeCharacterWrap,     //      UILineBreakModeClip,//截去多余部分     //      UILineBreakModeHeadTruncation,//截去头部     //      UILineBreakModeTailTruncation,//截去尾部     //      UILineBreakModeMiddleTruncation,//截去中间     //  } UILineBreakMode;      //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为     label.baselineAdjustment = UIBaselineAdjustmentNone;     //  typedef enum {     //      UIBaselineAdjustmentAlignBaselines,     //      UIBaselineAdjustmentAlignCenters,     //      UIBaselineAdjustmentNone,     //  } UIBaselineAdjustment;   

?

[self.view addSubview:label];
?

?

更多属性参考:?http://www.cocoachina.com/wiki/index.php?title=UIFont

?

?

?

?

?

读书人网 >移动开发

热点推荐