change uitextview hyperlink color

Muzamil Hassan picture Muzamil Hassan · Nov 15, 2012 · Viewed 24.1k times · Source

I am using UITextView and i want to change the color of hyperlink which i use in this component. For example if UITextView is showing www.gmail.com then it shows up in blue color. I want to change that color.

Answer

Tim Windsor Brown picture Tim Windsor Brown · Jan 9, 2014

Huzzah! Apple have released a proper solution with iOS7! As explained in this answer you can use the linkTextAttributes property of a UITextView. A white, underlined link would look something like this:

yourTextView.linkTextAttributes = @{
    NSForegroundColorAttributeName: [UIColor whiteColor], 
    NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle]
};

or alternatively you could change the tintColor, since UITextView inherits from UIView and uses the tintColor property to colour links - see:

yourTextView.tintColor = [UIColor whiteColor];

Now your links can look epic!