Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make able to set NSBackgroundColorAttributeName. #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Lib/SETextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,37 @@ - (void)drawTextDecorations
}
#endif

#if TARGET_OS_IPHONE
- (void)drawTextBackgroundColorRect
{
[self.attributedText enumerateAttribute:NSBackgroundColorAttributeName inRange:NSMakeRange(0, self.attributedText.length) options:kNilOptions usingBlock:^(id value, NSRange range, BOOL *stop) {
if (!value) {
return;
}

for (SELineLayout *lineLayout in self.textLayout.lineLayouts) {
CGRect rect = [lineLayout rectOfStringWithRange:range];
if (!CGRectIsEmpty(rect)) {
UIColor *color = (UIColor *)value;
if (![color isKindOfClass: [UIColor class]]) {
return;
}
UIBezierPath *path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect))];
[path addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect))];

path.lineWidth = rect.size.height;
[color setStroke];

[path stroke];
}
}
}];
}
#endif


- (void)drawTextAttachmentsInContext:(CGContextRef)context
{
NSMutableSet *attachmentsToLeave = [[NSMutableSet alloc] init];
Expand Down Expand Up @@ -934,6 +965,10 @@ - (void)drawRect:(CGRect)dirtyRect
[self drawTextDecorations];
#endif

#if TARGET_OS_IPHONE
[self drawTextBackgroundColorRect];
#endif

[self drawTextAttachmentsInContext:context];

#if TARGET_OS_IPHONE
Expand Down