透明DTAttributedLabel

时间:2014-05-28 17:26:41

标签: ios dtcoretext

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

1 个答案:

答案 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];