• 【IOS】UILabel 属性及方法


     label.lineBreakMode = NSLineBreakByTruncatingTail;   //文尾省略号
     label.font = [UIFont fontWithName:@"AvenirNext-Bold" size:12];  //字体
     label.numberOfLines = 1;  //行数
     label.textAlignment = NSTextAlignmentLeft; /NSTextAlignmentCenter  //字体位置
    
     //混合样式的文字
     UIColor* textColor =  [UIColor whiteColor];
     NSString *text = [NSString stringWithFormat:@"%d/%d",index,count];
     NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text];
    
     [str addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(0,1)];
    
     [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"AvenirNext-Bold" size:30.0] range:NSMakeRange(0, 1)];
     [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"AvenirNext-DemiBold" size:15.0] range:NSMakeRange(1, 1)];
     [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"AvenirNext-DemiBold" size:10.0] range:NSMakeRange(2, (text.length - 2))];
     label.attributedText = str;
    
     //配合设置label的size,可以设置背景为圆角矩形
     label.layer.masksToBounds = YES;
     label.layer.cornerRadius = 2; //圆角半径
     label.layer.borderWidth = 0;
    
     // 
    - (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font {
        CGRect rect = [string boundingRectWithSize:CGSizeMake(320, 8000)//限制最大的宽度和高度
                                           options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                        attributes:@{NSFontAttributeName: font}//传人的字体字典
                                           context:nil];
        
        return rect.size;
    }
  • 相关阅读:
    SQL-W3School-高级:SQL ALIAS(别名)
    SQL-W3School-高级:SQL BETWEEN 操作符
    SQL-W3School-高级:SQL IN 操作符
    SQL-W3School-高级:SQL 通配符
    C语言实现定积分求解方法
    android使用webview上传文件(支持相册和拍照)
    POJ2349+Prim
    nyist 740 “炫舞家“ST(动态规划)
    paip.php eclipse output echo 乱码
    Deep Learning论文笔记之(八)Deep Learning最新综述
  • 原文地址:https://www.cnblogs.com/afluy/p/4992926.html
Copyright © 2020-2023  润新知