zoukankan      html  css  js  c++  java
  • UILabel + 导入字体

    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];

    1.设置文字颜色

      label.textColor = [UIColor orangeColor]; label2.textColor = [UIColor purpleColor];

      lable.textColor = [UIColor colorWithRed:222/255.0 green:59/255.0 blue:17/255.0 alpha:1];

    2.设置背景颜色

      label.backgroundColor = [UIColor clearColor];

    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;

     

  • 相关阅读:
    浅析七种经典排序算法
    一个可编辑与新增博客园文章的 Python 脚本
    快速排序的几种实现方式
    如何查找某个网站的(如:有道云笔记)的接口
    一键导出「有道云笔记」所有笔记
    2020年启蒙及小学识字练字APP或小程序测评榜
    2020年部编版小学二年级语文上册知识点(完整版)
    2020年部编人教版小学语文一年级下册知识点汇总
    换个角度,程序员爸爸应该关注一下
    计算机基础知识-I/O篇
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5138678.html
Copyright © 2011-2022 走看看