zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    阻止事件冒泡
    移动端开发
    angular6 管道多参数传输 Pipe
    在div上添加小三角
    angular6 使用@Input() @Output()
    angular6 想要获取页面某些事件 如 点击 window宽高等等
    如何将项目添加到git上
    使用vue-cli 搭建element-admin后台
    bootstrap4 常用样式类名 (供自己参考)
    键盘按下 keyCode 的值
  • 原文地址:https://www.cnblogs.com/yangqinglong/p/5154880.html
Copyright © 2011-2022 走看看