UILabel使用自定义字体
2015-08-17 16:31
453 查看
下载自定义字体(例如: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];
在 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];
相关文章推荐
- UIAutomator API浅析
- POJ 1019 Number Sequence (循环递增序列的的第K个值)
- POJ 1679 The Unique MST(判断最小生成树_Kruskal)
- 【CSS3 入门教程系列】CSS3 Media Queries 实现响应式设计
- 如何诊断RAC系统中的gc cr multi block request
- String,StringBuffer,StringBuilder以及线程安全性
- android stuio修改代码参考线和智能换行
- ArcServer10 安装中提示The following features cannot not be installed due to missing prerequisites"
- UITextView高度随文字自动增加
- iOS基础-UIKit框架-多控制器管理-实例:私人通讯录
- [LeetCode] Single Number III ( a New Questions Added today)
- android studio 新建项目 界面一直停在 【“building ‘ 项目名’ gradle project info”】
- UITableView使用详解
- [Leetcode] Longest Consecutive Sequence
- ZOJ 3210 A Stack or A Queue ? 水
- HDFS列式存储Parquet与行式存储(Avro)性能测试-Benchmark(hadoop, Spark, Scala)
- 【CF 570D】Tree Requests
- IOS UItableView得到group如何摆脱的剪裁线条样式问题
- request 和 response 的页面跳转
- POJ_3080_BlueJeans