Attributed Text Center Alignment

前端 未结 10 2440
故里飘歌
故里飘歌 2020-12-13 17:06

I have tried everything but cannot seem to center this text. Can someone please tell me where the error is.

NSMutableParagraphStyle *paragraphStyle = NSMutab         


        
10条回答
  •  感情败类
    2020-12-13 17:24

    You can set the center alignment using this. Remember to set range.

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setAlignment:NSTextAlignmentCenter];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
    

提交回复
热议问题