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

add NSAttributedString attributes support for links, support UIColor … #549

Merged

Conversation

gblazex
Copy link
Contributor

@gblazex gblazex commented Jul 2, 2015

…(not just for Foreground)

Add support for the following attributes for links (default, active, inactive):

NSFontAttributeName
NSBackgroundColorAttributeName
NSForegroundColorAttributeName
NSUnderlineColorAttributeName
NSUnderlineStyleAttributeName
NSStrokeWidthAttributeName
NSStrokeColorAttributeName
NSKernAttributeName
NSLigatureAttributeName

Also uniformly support UIColor for attribute values not just for Foreground color (as it was previously).

@gblazex
Copy link
Contributor Author

gblazex commented Jul 2, 2015

before, you had to write this tedious mess:

self.activeLinkAttributes =  @{
    (NSString *)kCTUnderlineStyleAttributeName:
        @NO,
    kTTTBackgroundFillColorAttributeName:
        (__bridge id)[[UIColor colorWithWhite:0 alpha:0.3] CGColor],
    kTTTBackgroundStrokeColorAttributeName:
        (__bridge id)[[UIColor colorWithWhite:1 alpha:0.5] CGColor],
    kTTTBackgroundLineWidthAttributeName:
        @1,
    kTTTBackgroundCornerRadiusAttributeName:
        @4
};

after, you can just simply do:

self.activeLinkAttributes =  @{
    NSUnderlineStyleAttributeName           : @NO,
    NSBackgroundColorAttributeName          : [UIColor colorWithWhite:0 alpha:0.3],
    kTTTBackgroundStrokeColorAttributeName  : [UIColor colorWithWhite:1 alpha:0.5],
    kTTTBackgroundLineWidthAttributeName    : @1,
    kTTTBackgroundCornerRadiusAttributeName : @4
}; 

return [color isKindOfClass:[UIColor class]] ? [color CGColor] : (__bridge CGColorRef)color;
}

static inline CTFontRef ctFontRefFromUIFont(UIFont * font) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ct be CT in this function name?

@getaaron
Copy link
Contributor

getaaron commented Sep 6, 2015

This looks great, @galambalazs I added a few minor suggestions.

@gblazex
Copy link
Contributor Author

gblazex commented Sep 6, 2015

Sure whatever way you want to do it. You can either merge it and add your own changes, or simply do your own PR.

I doubt I'll have time to edit this PR in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants