0118——UILabel和导入字体
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];
1.设置文字颜色
label.textColor = [UIColor orangeColor];
label2.textColor = [UIColor purpleColor];
2.设置背景颜色
label.backgroundColor = [UIColor clearColor];
lable.textColor = [UIColor colorWithRed:222/255.0 green:59/255.0 blue:17/255.0 alpha:1];
3.设置文字位置
label.textAlignment = UITextAlignmentLeft;
4.设置label的行数 0表示多行,自适应
label.numberOfLines = 2;
5.设置阴影
label.shadowColor = [UIColor redColor];
label.shadowOffset = CGSizeMake(1.0,1.0);
6.设置文字过长时的显示格式
label.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
enum {
UILineBreakModeWordWrap = 0,
UILineBreakModeCharacterWrap,
UILineBreakModeClip,//截去多余部分
UILineBreakModeHeadTruncation,//截去头部
UILineBreakModeTailTruncation,//截去尾部
UILineBreakModeMiddleTruncation,//截去中间
} UILineBreakMode;
7.导入字体包设置自己的字体
在网上下载好字体文件,拖拽的到工程中,选好target


在plist中加入一行,写入字体文件打开后的名字

lable.font = [UIFont fontWithName:@"DFGirlW3-B5" size:20];
8.计算字符串的长度
a.确定一个大的容器,width或者height 一定,另一个可变,变化的变量一定要大
b.确定计算font
c.boundingRectWithSize
NSString * str = @"The NSString class declares the programmatic interface for an object that manages immutable strings.";
UIFont * font = [UIFont fontWithName:@"DFGirlW3-B5" size:20];
NSDictionary * attrDic = @{NSFontAttributeName:font};
CGSize bigsize = CGSizeMake(300, 3000);
CGSize realsize = [str boundingRectWithSize:bigsize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrDic context:nil].size;
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, realsize.width, realsize.height)];
label.text = str;
label.backgroundColor =[UIColor blackColor];
label.font = [UIFont fontWithName:@"DFGirlW3-B5" size:20];
label.textColor = [UIColor colorWithRed:222/255.0 green:59/255.0 blue:17/255.0 alpha:1];
label.textAlignment =NSTextAlignmentLeft;
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
0118——UILabel和导入字体的更多相关文章
- UILabel + 导入字体
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)]; 1.设置文字颜色 label.textC ...
- css3 导入字体
在CSS中导入字体或是字体ICON @font-face{ src: url("具体的字体地址"), url("具体的字体地址"); }
- iOS运用runtime全局修改UILabel的默认字体
iOS运用runtime全局修改UILabel的默认字体 一.需求背景介绍 在项目比较成熟的基础上,遇到了这样一个需求,应用中需要引入新的字体,需要更换所有Label的默认字体,但是同时,对于一些特殊 ...
- PHPstorm如何导入字体主题
概要: 今天在安装phpstorm的时候发现导入字体主题时,出了问题,这个问题总是困惑我,并且曾经遇到过,没记录下来,所以想着这次记录下来吧.网上搜的稀里糊涂的,还是自己做个summary! 前提: ...
- 如何设置UILabel中的字体的间距
cell.teacherDescriptionLabel.text = content; cell.teacherDescriptionLabel.textAlignment = NSTextAlig ...
- 微信小程序如何导入字体图标
前提:我们已经拥有了从阿里图标库下载下来的一系列的字体图标文件1:找个其中的ttf格式的文件,然后打开https://transfonter.org/网站2:点击Add fonts按钮,加载ttf格式 ...
- UILabel字体加粗等属性和特效
/* Accessing the Text Attributes text property font property textColor property textAlignment pr ...
- iOS UILabel详解
1.创建 CGRect rect = CGRectMake(100, 200, 50, 50); UILabel *label = [[UILabel alloc] initWithFrame:rec ...
- UILabel 整理
UILabel 多行文字自动换行 (自动折行) 1.UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 3 ...
随机推荐
- oracle学习笔记(二)表的查询
--oracle表的管理 --创建表 )); --删除表 drop table users; --创建表 ),xm ),sex ),birthday date,sal ,)); ),cnmae )); ...
- .net简单页面后台绑定下拉框,按钮,分页 前台aspx页面
一.aspx页面 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Updat ...
- delete语句与reference约束 FK_subplan_job_id冲突问题,导致job无法删除解决办法
在SQL Server 2008上删除已运行维护计划后,维护计划job没有自动删除掉,手工再删除维护计划job,提示删除失败. 错误现象:delete 语句与 reference 约束"F ...
- poj3090欧拉函数求和
E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB ...
- C#通过生成ini文件,记住用户关闭程序之前的选择+忽略跨线程检查
1.在类的里面添加 //写配置文件 [DllImport("kernel32")] private static extern long WritePrivateProfileSt ...
- map和reduce
map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. map()传入的第一个参数是f,即函数对象本身.由于 ...
- 动态编译添加php模块
注意:转载请注明出处:http://www.programfish.com/blog/?p=85 在很多时候我们用linux里搭建web服务器的时候会需要编译安装php套件,而在编译安装后可能又会需要 ...
- 新版TeamTalk部署教程(蓝狐)
http://www.bluefoxah.org/teamtalk/new_tt_deploy.html
- MicrosoftSQLServer中的锁模式
在SQL Server数据库中加锁时,除了可以对不同的资源加锁,还可以使用不同程度的加锁方式,即锁有多种模式,SQL Server中锁模式包括: 1.共享锁 SQL Server中,共享锁用于所有的只 ...
- POI导入数据
package util; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.I ...