1

DTCoreTextを使用すると、DTAttributedLabels は常に白い背景になります。を変更し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 に答える