天天看点

设置首行缩进

主要使用TextKit方法。

具体代码如下:

NSMutableParagraphStyle *paraStyle01 = [[NSMutableParagraphStyle alloc] init];
    paraStyle01.alignment = NSTextAlignmentLeft;  //对齐
    paraStyle01.headIndent = f;//行首缩进
    paraStyle01.firstLineHeadIndent = f;//首行缩进
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@"首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进首行缩进" attributes:@{ NSParagraphStyleAttributeName : paraStyle01}];

    UILabel *_content = [[UILabel alloc] initWithFrame:CGRectMake(,, , )];
    _content.numberOfLines=;
    _content.font = [UIFont systemFontOfSize:];
    _content.backgroundColor = [UIColor redColor];
    _content.attributedText = attrText;
    [self.view addSubview:_content];
           

效果图:

设置首行缩进

继续阅读