UILabel---.tff格式字体

1.将下载的.tff文件导入文件并且导入工程 

如果导入的时候没有导入工程,手动配置

project->build phases->copyBundleResources里面添加导入的字体

2.到plist文件中修改配置

3,在mac中打开字体,显示的标题为字体名字

4.如何计算字符串的长宽

1.确定容器的大小

a.width或者height一方固定

b.变化的一方变量一定要足够大

2.确定计算的font,

3.调用boundingRectWithSize

NSString *str =@"

the underlying attributed string drawn by the label, if set, the label ignores the properties above";//要显示的字

UIFont *font = [UIFont fontWithName:@"Du Bellay"size:20];//设置字体,大小

NSDictionary *attrDic = @{NSFontAttributeName:font};

CGSize bigSize = CGSizeMake(300,3000);//一方固定,一方足够大

CGSize realSize = [str boundingRectWithSize:bigSize option:NSStringDrawingUsesLineFragmentOrigin attributes:attrDic context:nil].size;

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10,30,realSize.width,realSize.height)];

label.text = str;

label.font =[UIFont fontWithName:@"Du Bellay" size:20];

labe.textColour = [UIColour colorWithRed:222/225.0 green:59/255.0 blue:17/255.0 alpha:1];

//对齐方式

label.textAlignment = NSTextAlignmentLeft;

lable.backgroundColor = [UIColor yellowColor];

//设置label显示多少行,0表示多行

label.numberOfLines = 0;

设置换行方式,按字符换行

label.lineBreakMode = NSLineBreakByWordWrapping;

//投影

label.shadowOffset = CGSizeMake(-1,-1);

label.shadowColour = [UIColour redColor];

[self.view addSubview:label];

}

 

附正则表达式网址:http://www.jb51.net/tools/zhengze.html

posted @ 2016-01-24 11:36  蜗牛才是大牛  阅读(560)  评论(0编辑  收藏  举报