Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found indeed another way <strong>without using a webview</strong> but keep in mind that this uses <strong>private API</strong> and may be rejected in appstore:</p> <p><strong>EDIT:</strong> My app got approved by apple although the private api usage!</p> <p>First declare a category on UITextView with the methods</p> <pre><code>- (id)contentAsHTMLString; - (void)setContentToHTMLString:(id)arg1; </code></pre> <p>They are just doing the following:</p> <pre><code>- (id)contentAsHTMLString; { return [super contentAsHTMLString]; } - (void)setContentToHTMLString:(id)arg1; { [super setContentToHTMLString:arg1]; } </code></pre> <p>Now write a method for colorful links:</p> <pre><code>- (void) colorfillLinks; { NSString *contentString = [self.textViewCustomText contentAsHTMLString]; contentString = [contentString stringByReplacingOccurrencesOfString:@"x-apple-data-detectors=\"true\"" withString:@"x-apple-data-detectors=\"true\" style=\"color:white;\""]; [self.textViewCustomText setContentToHTMLString:contentString]; } </code></pre> <p>It does set the style attribute with a specific color on all types of links. </p> <p>UITextViews are rendered Webiview like via divs so you could even go further and color each link type separately: </p> <pre><code>&lt;div&gt;&lt;a href="http://www.apple.com" x-apple-data-detectors="true" style="color:white;" x-apple-data-detectors-type="link" x-apple-data-detectors-result="0"&gt;http://www.apple.com&lt;/a&gt;&lt;/div&gt; </code></pre> <p>The <code>x-apple-data-detectors-type="link"</code> is the indicator for the exact type of the link</p> <p><strong>EDIT</strong></p> <p>On <code>iOS7</code>this is no longer working. In iOS7 you could easily change the link color of UITextViews by setting the tint color. You should not call </p> <pre><code>- (id)contentAsHTMLString; </code></pre> <p>anymore, you'll get an exception. Instead do the following if you want to support iOS 7 and below:</p> <pre><code>- (void) colorfillLinks; { if ([[[UIDevice currentDevice] systemVersion] floatValue] &gt;= 7) { self.tintColor = [UIColor colorWithRed:79.0/255.0 green:168.0/255.0 blue:224.0/255.0 alpha:1.0]; } else if(![self isFirstResponder ]) { NSString *contentString = [self contentAsHTMLString]; contentString = [contentString stringByReplacingOccurrencesOfString:@"x-apple-data-detectors=\"true\"" withString:@"x-apple-data-detectors=\"true\" style=\"color:#DDDDDE;\""]; [self setContentToHTMLString:contentString]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload