NSMutableParagraphStyle 实现文本缩进

时间:2022-09-26 23:15:53

   



 UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 100, 300, 100)];

    NSString *detail = @"看哈开机动画科技时代看";

    textView.text = detail;

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

    paragraphStyle.lineSpacing = 8; //行距

    paragraphStyle.firstLineHeadIndent = 80;

    

    NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:15], NSParagraphStyleAttributeName:paragraphStyle};

    

    textView.attributedText = [[NSAttributedString alloc]initWithString: textView.text attributes:attributes];

    [self.view addSubview:textView];




NSMutableParagraphStyle是一个枚举值,可以点进去看看自己所需要的