NSString *hintStr = @"输入材料标题搜索材料\n注:可根据材料序号直接搜索, 如TPO23"; CGSize size = [toolset returnTextStringSizeWithString:hintStr withBoundSize:CGSizeMake(Main_Screen_Width - 72, MAXFLOAT) withFont:FZHei(15)]; self.mHintLabelLayoutH.constant = size.height + 20; [self.mHitLabel setNeedsLayout]; NSMutableAttributedString *prefixAttr = [[NSMutableAttributedString alloc] initWithString:hintStr]; [prefixAttr addAttribute:NSFontAttributeName value:FZHei(17) range:NSMakeRange(0, hintStr.length)]; [prefixAttr addAttribute:NSForegroundColorAttributeName value:ColorHui range:NSMakeRange(0, hintStr.length)]; [prefixAttr addAttribute:NSForegroundColorAttributeName value:HexRGB(0xc0c0c0) range:NSMakeRange(11, 21)]; [prefixAttr addAttribute:NSFontAttributeName value:FZHei(13) range:NSMakeRange(11, 21)]; NSMutableParagraphStyle *paragraphString = [[NSMutableParagraphStyle alloc] init]; [paragraphString setLineSpacing:8]; //设置行间距 [prefixAttr addAttribute:NSParagraphStyleAttributeName value:paragraphString range:NSMakeRange(0, hintStr.length)]; self.mHitLabel.attributedText = prefixAttr;
UILabel *dataLabel = [[UILabel alloc] init]; dataLabel.backgroundColor = [UIColor clearColor]; dataLabel.text = @"我是文字文字文字文字文字文字文字文字文字文字文字"; dataLabel.textColor = RGBACOLOR(97, 96, 98, 1); dataLabel.font = [UIFont fontWithName:@"Arial" size:14]; dataLabel.numberOfLines = 0; [backImage addSubview:dataLabel]; //富文本设置文字行间距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init]; paragraphStyle.lineSpacing = 4; NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle}; dataLabel.attributedText = [[NSAttributedString alloc]initWithString:dataLabel.text attributes:attributes]; //获取设置文本间距以后的高度 CGRect fram = [dataLabel.attributedText boundingRectWithSize:CGSizeMake(210, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil];