سؤال

I've found that drawing borders was implemented in DTCoreText. But can't find any resources on how to do that. I receive some html text, modify it and then display it using DTAttributedTextContentView. So my question is, can i somehow add border? If yes maybe someone has an example or knows where to find how to do this? Thanks in advance.

هل كانت مفيدة؟

المحلول

I didn't found any solution to this, so i did a workaround. In case anyone will be looking for this: I created DTCSSStylesheet with specifying a css for html tags with padding. And then i DTCoreTextContentViewDelegate method drew a border.

- (BOOL)attributedTextContentView:(DTAttributedTextContentView *)attributedTextContentView shouldDrawBackgroundForTextBlock:(DTTextBlock *)textBlock frame:(CGRect)frame context:(CGContextRef)context forLayoutFrame:(DTCoreTextLayoutFrame *)layoutFrame
{   
    UIBezierPath *roundedFrame = [UIBezierPath bezierPathWithRoundedRect:frame cornerRadius:5];

    CGColorRef color = [textBlock.backgroundColor CGColor];
    if (color)
    {
        CGContextSetFillColorWithColor(context, color);
    }
    CGContextAddPath(context, [roundedFrame CGPath]);
    CGContextFillPath(context);

    CGContextAddPath(context, [roundedFrame CGPath]);
    CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
    CGContextStrokePath(context);

    return NO; // draw standard background
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top