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

Link/Code text colour doesn't work #14

Open
swaterfall opened this issue Nov 11, 2018 · 4 comments
Open

Link/Code text colour doesn't work #14

swaterfall opened this issue Nov 11, 2018 · 4 comments

Comments

@swaterfall
Copy link

Setting the colour attribute for Link/Code doesn't work:

To recreate just add the following code to example project in Exemple2ViewController:

markdownParser.link.color = UIColor.red
markdownParser.code.color = UIColor.red

@martinprot
Copy link

Yes, I confirm the bug. link colors and font just won't work.

@Coeur
Copy link
Collaborator

Coeur commented Nov 23, 2018

markdownParser is returning an NSAttributedString. Colors for link will depend on the UI element: UILabel, UITextView and NSTextView all behave differently.

See what I wrote in this other project: https://github.com/laptobbe/TSMarkdownParser/blob/3.x/TSMarkdownParser/TSMarkupParser.h:

/**
 * markupParser setting for NSLinkAttributeName
 *
 * When YES, references to URL are lost and you have freedom to customize the appearance of text.
 *
 * When NO, reference to URL are kept with NSLinkAttributeName and restrictions to customize the appearance of links apply:
 *
 * * UILabel is forcing all links to be displayed blue and underline, links aren't clickable
 *
 * * UITextView's tintColor property is controlling all links color, links are clickable
 *
 * * NSTextView's linkTextAttributes property is controlling all links attributes
 *
 * If you want clickable links with an UILabel subclass, you should leave skipLinkAttribute to NO and consider using KILabel, TTTAttributedLabel, FRHyperLabel, ... As a bonus, all will lift off the UILabel appearance restrictions for links.
 */
@property (nonatomic, assign) BOOL skipLinkAttribute;

So, you need:

  • to specify if you need your link to be clickable or not
  • to specify what is the UI container that you use

And only then I may be able to help.

@Coeur
Copy link
Collaborator

Coeur commented Nov 23, 2018

@swaterfall the example that you've pinpointed at is using UITextView. So you got the choices:

a. UITextView's tintColor property is controlling all links color, links are clickable.
b. You remove NSLinkAttributeName, and you can get a mix of colors, but links are no more clickable.
c. You subclass UITextView and you add your own magic (you'll need your own UIGestureRecognizer) to make links both clickable and with different colors. It's complex, but you may get a partial idea from the second part of this answer: https://stackoverflow.com/a/49443814/1033581

@martinprot
Copy link

@Coeur in my case, the markdown was applied to a UILabel. Links remains blue. In my particular case, I don't need a clicable link.
I cannot find any equivalent of TSMarkdownParser.skipLinkAttribute in Haring.

Beyond of this, what is the point about restricting the style of a link? I mean : if I explicitely set parser.link.color, why to prevent the expected behaviour?

Thanks.

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

No branches or pull requests

3 participants