1

使用DTCoreTextDTAttributedLabels 始终具有白色背景。改变backgroundColor不做任何事情。显示使用 CSS 设置背景颜色,但将其设置为清除显示白色背景。

4

1 回答 1

0

以下代码为我使用“DTCoreText Library”设置“DTAttributedLabel”的背景颜色。

 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];
于 2015-06-24T13:43:26.093 回答