1.將下載的.tff文件導入文件而且導入工程 html
若是導入的時候沒有導入工程,手動配置正則表達式
project->build phases->copyBundleResources裏面添加導入的字體app
2.到plist文件中修改配置字體
3,在mac中打開字體,顯示的標題爲字體名字ui
4.如何計算字符串的長寬.net
1.肯定容器的大小htm
a.width或者height一方固定字符串
b.變化的一方變量必定要足夠大string
2.肯定計算的font,it
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