使用DTCoreText,DTAttributedLabel
始终具有白色背景。更改backgroundColor
不会做任何事情。显示使用CSS设置背景颜色,但将其设置为清除显示白色背景。
答案 0 :(得分:0)
以下代码为我设置背景颜色为" DTAttributedLabel"使用" DTCoreText Library"。
NSString *html = @"<p>Some Text</p>";
CGRect frame = self.lblText.frame; // self.lblText is a label from storyboard view controller
DTAttributedLabel *attLbl = [[DTAttributedLabel alloc] initWithFrame:frame];
attLbl.backgroundColor = [UIColor grayColor];
NSDictionary *options = @{
DTDefaultFontFamily: @"Avenir Next Heavy",
DTDefaultFontSize: @36.0,
NSTextSizeMultiplierDocumentOption: @1.05,
DTDefaultTextColor: [UIColor redColor],
DTDefaultTextAlignment: [NSNumber numberWithInt:kCTRightTextAlignment]
};
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data options:options documentAttributes:NULL];
attLbl.attributedString = string;
[self.view addSubview: attLbl];