webview.backgroundColor = [
UIColor
clearColor];
webview.opaque =
NO
;
webview.dataDetectorTypes =
UIDataDetectorTypeNone
;
NSString
*webviewText = @
"<style>body{margin:0;background-color:transparent;font:16px/18px Custom-Font-Name}</style>"
;
NSString
*htmlString = [webviewText stringByAppendingFormat:@
"%@"
, textview.text];
[webview loadHTMLString:htmlString baseURL:
nil
];
补充:
也可以解决。。。。。,
CGFloat heih = 20;
NSString * cLabelString = @"如果对“”的计算不满意,可以继承UILabel来自定义label,同时重写label的“sizeThatFits:”方法,这样自定义label的“sizeToFit”行为就会被改变如果对“”的计算不满意,可以继承UILabel来自定义label,同时重写label的“sizeThatFits:”方法,这样自定义label的“sizeToFit”行为就会被改变如果对“”的计算不满意,可以继承UILabel来自定义label,同时重写label的“sizeThatFits:”方法,这样自定义label的“sizeToFit”行为就会被改变";
UILabel * cLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, heih, 280, 200)];
cLabel.numberOfLines = 3;
cLabel.font = [UIFont systemFontOfSize:16];
cLabel.textColor = [UIColor grayColor];
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:cLabelString];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:30];
[paragraphStyle1 setLineBreakMode:NSLineBreakByTruncatingTail];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [cLabelString length])];
[cLabel setAttributedText:attributedString1];
NSLog(@"the label bounds : %@", NSStringFromCGRect(cLabel.frame));
[cLabel sizeToFit];
NSLog(@"the label bounds : %@", NSStringFromCGRect(cLabel.frame));
[self.window addSubview:cLabel];