zoukankan      html  css  js  c++  java
  • 【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;
    }
  • 相关阅读:
    python获取当前路径
    python的StringIO
    python判断两个文件是否相同
    Linux查找文件内容
    python日志syslog运用
    python获取当前运行程序的名字
    python连接Linux命令行
    python预编译函数compile,exec,eval
    python日志模块
    Scala安装教程
  • 原文地址:https://www.cnblogs.com/afluy/p/4992926.html
Copyright © 2011-2022 走看看