UILabel使用自定义字体
2012-03-21 17:48
323 查看
code 4
下载自定义字体(例如:Blazed.ttf)后,拖入项目当中。
在 Supporting Files 中找到 (项目名称)-info.plist, 添加 Fonts provided by application 项, 打开对应的数组,可以设置多个字体,在Item0中 输入Blazed.ttf。
在程序中通过字体family name,找出字体名字。然后使用
C代码
或者
C代码
例外还有其他设置:
C代码
C代码
//设置阴影
[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;
C代码
更多属性参考: http://www.cocoachina.com/wiki/index.php?title=UIFont
下载自定义字体(例如:Blazed.ttf)后,拖入项目当中。
在 Supporting Files 中找到 (项目名称)-info.plist, 添加 Fonts provided by application 项, 打开对应的数组,可以设置多个字体,在Item0中 输入Blazed.ttf。
在程序中通过字体family name,找出字体名字。然后使用
C代码
label.font = [UIFont fontwithname:@"Blazed" size:42];
或者
C代码
UIFont *tfont = [UIFont fontWithName:@"Blazed" size:42]; label.font = tfont;
例外还有其他设置:
C代码
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];
C代码
//设置阴影
[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;
C代码
[self.view addSubview:label];
更多属性参考: http://www.cocoachina.com/wiki/index.php?title=UIFont
相关文章推荐
- UILabel使用自定义字体
- UILabel使用自定义字体
- 在iPhone应用中使用自定义字体
- ionic2中使用自定义字体图标
- Android进阶UI之使用自定义字体
- Cocos2d-x 3.10 使用BMFont 制作自定义位图字体.fnt文件
- iOS中使用自定义ttf/ttc字体,以及cocosbuilder中指定字体的方法
- 使用 UIFontWDCustomLoader 载入自定义字体
- IOS使用自定义字体
- Unity3D BMFont使用图片自定义字体(无需字体文件)
- Windows Phone:自定义字体在xaml和代码中使用
- 如何使用自定义字体
- IOS使用自定义字体
- Android中使用自定义的字体
- Unity3D BMFont使用图片自定义字体(无需字体文件) .
- iOS使用自定义字体
- css自定义字体font-face的兼容和使用
- [cocos2d-x] --- 使用位图工具自定义字体
- 在iPhone应用中使用自定义字体
- css 使用@font-face 嵌入自定义字体或字体图标方法笔记