• UILabel的简单用法和实际操作


    1、UILabel
     
    **//设置文字

    label.text = @"欢迎收看灌篮高手,我是安溪教练";
    **//设置文字颜色
    label.textColor = [UIColor grayColor];
    **//默认17号字体
    label.font = [UIFont systemFontOfSize:34];
    **//对齐方式
    label.textAlignment = NSTextAlignmentCenter;
    **//设置阴影
    label.shadowColor = [UIColor redColor];
    //设置阴影映射大小(坐标),默认CGSizeMake(0, -1)
    label.shadowOffset = CGSizeMake(-2, -2);
    ***//断句,展示缩略
    label.lineBreakMode = NSLineBreakByTruncatingTail;
    **//行数0为自动匹配行数
    label.numberOfLines = 1;
    ***//字体是否适应宽度(Size无效)(将宽度充满)
    label.adjustsFontSizeToFitWidth = YES;

    //最小字体比例(缩放)  

    label.minimumScaleFactor = 0.9;

    **//label背景色

    label.backgroundColor = [UIColor yellowColor];

    //设置高亮颜色

    label.highlightedTextColor = [UIColor greenColor];

    //开启高亮状态

    label.highlighted = YES;

    //是否隐藏高亮状态

    label.hidden = NO;

    2、UIFont

    //打印苹果自带字体

    for (NSString* str in [UIFont familyNames]) {

            NSLog(@"%@",str);

           NSArray* arr = [UIFont fontNamesForFamilyName:str];

            for (NSString* str1 in arr) {

                NSLog(@"%@",str1);

            }

        }

    //斜体

    [UIFont italicSystemFontOfSize:50];
    //字体加粗
    [UIFont boldSystemFontOfSize:50];
    //设置系统字体

    [UIFont systemFontOfSize:10];

    //设置自定义字体

    [UIFont fontWithName:@"Heiti TC" size:25];

    //修改字体

    [[UIFont systemFontOfSize:10] fontWithSize:50];

    富文本 

    3、NSAttributedString

    NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:string attributes:dictA];

    label.attributedText = attribute;

    • addAttributes//分段操作字符串

    (字典类型)

    NSFontAttributeName:[UIFont systemFontOfSize:20],//字体大小

    NSForegroundColorAttributeName:[UIColor greenColor]//字体颜色

    NSBackgroundColorAttributeName:[UIColor grayColor]//字体背景颜色

    NSParagraphStyleAttributeName:paragraph//段落属性

    NSObliquenessAttributeName:@0.5 //斜体

    NSStrokeColorAttributeName:[UIColor whiteColor],//边线颜色

    NSStrokeWidthAttributeName:@2,//描边

    NSKernAttributeName:@20,//字间距

    NSStrikethroughStyleAttributeName:@2,//删除线

    NSUnderlineStyleAttributeName:@1,  //下划线

    段落  
    4、NSMutableParagraphStyle 属性

        //行间距

        paragraph.lineSpacing = 10;

        //段间距

        paragraph.paragraphSpacing = 50;

        //头尾间距(第一行)

        paragraph.firstLineHeadIndent = 50;

    计算label高度

    CGSize size1 =[string boundingRectWithSize:CGSizeMake(self.view.frame.size.width-40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

    竖直文本Size计算

       CGSize size =  [string boundingRectWithSize:CGSizeMake(字体大小, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

    自适应

    + sizeToFit

    + sizeThatFits:(CGSize)

  • 相关阅读:
    大数据挖掘算法篇之K-Means实例
    断篇-金融大数据最佳实践总结篇
    网络爬虫之Windows环境Heritrix3.0配置指南
    开源中文分词框架分词效果对比smartcn与IKanalyzer
    Eclipse整合Tomcat开发Dynamic Web Project环境总结
    c#系统消息类封装
    Uploadify v3.2.1 参数说明
    js 或 且 非
    数据注解特性--NotMapped
    SQLServer2008/2005 生成数据字典语句
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5268677.html
Copyright © 2020-2023  润新知