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;

     

  • 相关阅读:
    D. Longest Subsequence
    线段树入门HDU_1754
    poj_2503(map映射)
    HDU_4826
    poj_2251
    day 44 单表查询,多表查询
    day43 字段的修改、添加和删除,多表关系(外键),单表详细操作(增删改查)
    day 42 数据库的配置、数据库与表的一些剩余操作、用户操作、数据库表的引擎、数据库的模式、mysql支持的数据类型、约束
    day41 数据库介绍、数据库基本操作
    day 40 线程队列、线程定时器、进程池和线程池、同步与异步、用多线程来写socket服务端与客户端
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5138678.html
Copyright © 2011-2022 走看看