UILabel設定行間距方法
阿新 • • 發佈:2019-02-06
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];