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

  • 相关阅读:
    RTK-Mannual-1-User Requirements&Installation and Uninstallation&Real-Time Positioning with RTKNAVI
    第一章-1.四元素的定义和性质
    ubuntu下的公式编辑器-latex
    SL-IMU-5、6-惯性导航解算方法以及惯性导航误差分析
    卫星导航系统-第16讲-船用惯性导航系统与卫星导航系统的组合-2
    卫星导航系统-第16讲-船用惯性导航系统与卫星导航系统的组合-1
    卫星导航系统-第14讲-差分定位方法-2
    卫星导航系统-第14讲-差分定位方法-1
    卫星导航系统-第13讲-差分定位方法-2
    【无线安全实践入门】破解WiFi密码的多个方法
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5268677.html
Copyright © 2011-2022 走看看