UILabel设定行间距方法

30074人阅读 评论(0) 收藏 举报
分类:
NSString *textStr = @"iPhone规定:任何应用想访问麦克风,必须被授权麦克风服务。请进入“设置”->“隐私”->“麦克风”中打开QQ空间的麦克风服务。";
        UIFont *textFont = [UIFont systemFontOfSize:14];
        CGSize textSize = [textStr sizeWithFont:textFont
                              constrainedToSize:CGSizeMake(bounds.size.width - 40, QZONE_SCREEN_HEIGHT)];;
        UILabel *openMicPrivilegeTipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, textSize.width, textSize.height)];
        openMicPrivilegeTipsLabel.textColor = DefaultDescriptionText2ColorInDefaultTheme;
        openMicPrivilegeTipsLabel.text = textStr;
        openMicPrivilegeTipsLabel.backgroundColor = [UIColor clearColor];
        openMicPrivilegeTipsLabel.textAlignment = UITextAlignmentLeft;
        openMicPrivilegeTipsLabel.font = [UIFont systemFontOfSize:14];
        openMicPrivilegeTipsLabel.numberOfLines = 0;
        
        // 调整行间距
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textStr];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:6];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [textStr length])];
        openMicPrivilegeTipsLabel.attributedText = attributedString;
        
        [_tipsBG addSubview:openMicPrivilegeTipsLabel];
        [openMicPrivilegeTipsLabel sizeToFit];

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1211134次
    • 积分:11066
    • 等级:
    • 排名:第1515名
    • 原创:108篇
    • 转载:152篇
    • 译文:0篇
    • 评论:187条
    最新评论