NSParagraphStyle 的属性

UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    label.font = [UIFont systemFontOfSize:14];
    label.numberOfLines = 0;
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.right.offset(-20);
        make.top.offset(160);
    }];
    NSString * desc = @"这是一段titlte文案,这是一段titlte文案,这是一段titlte文案,这是一段titlte文案后面是一个换行\nThis morning (March 29th), most cities and counties in Guangdong were cloudy and covered with light fog. Some areas in Qingyuan, Shaoguan and Zhaoqing saw dense fog with visibility of less than 500 meters.\n\n这是一段titlte文案,后面是一个换行\n";
    NSMutableParagraphStyle * style = [NSMutableParagraphStyle defaultParagraphStyle].mutableCopy;
    style.paragraphSpacing = 10; //当前段落和下一个段落的距离
    style.paragraphSpacingBefore = 5;//当前段落和上一个段落的距离
    style.lineSpacing = 20;//当前行和下一行的距离,空白行也存在间距,这个间距在行下
//    style.lineHeightMultiple = 2.0; //这个间距在行上
    style.firstLineHeadIndent = 30; //当前段落第一行的偏移量
    style.headIndent = 20;  //当前段落其他行的偏移量
    style.lineBreakMode = NSLineBreakByWordWrapping;//截断模式
//    style.tailIndent = -16; //为正数时代表显示宽度,为负数时代表距离右边的间距
//    style.alignment = NSTextAlignmentRight; //对齐方式
    //书写方向
//    style.baseWritingDirection = NSWritingDirectionRightToLeft;
    style.hyphenationFactor = 1.0; //0 or 1
    NSDictionary * dict = @{
                            NSFontAttributeName:[UIFont systemFontOfSize:18],
                            NSForegroundColorAttributeName:[UIColor blackColor],
                            NSParagraphStyleAttributeName:style,
                            NSBackgroundColorAttributeName:[UIColor redColor]
                            };
    NSAttributedString * attr = [[NSAttributedString alloc] initWithString:desc attributes:dict];
    label.attributedText = attr;

 

转载于:https://www.cnblogs.com/gulong/p/10628074.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值