I had a UITextView
that detects phone numbers and links, but this overrides my fontColor
and change it to blueColor
. Is there a way to format the color of auto detected links, or should I try a manual version of this function?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- Get the NSRange for the visible text after scroll
- how do you prevent page scroll in textarea on mobi
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
I found indeed another way without using a webview but keep in mind that this uses private API and may be rejected in appstore:
EDIT: My app got approved by apple although the private api usage!
First declare a category on UITextView with the methods
They are just doing the following:
Now write a method for colorful links:
It does set the style attribute with a specific color on all types of links.
UITextViews are rendered Webiview like via divs so you could even go further and color each link type separately:
The
x-apple-data-detectors-type="link"
is the indicator for the exact type of the linkEDIT
On
iOS7
this is no longer working. In iOS7 you could easily change the link color of UITextViews by setting the tint color. You should not callanymore, you'll get an exception. Instead do the following if you want to support iOS 7 and below:
Instead of using an UITextView, I used an UIWebView and enabled the "auto-detect links". To change the link color, just created a regular CSS for the tag.
I used something like this:
You can Change the Hyperlink Color in a TextView by the following:
In the Nib file, you can go to the Properties Window and change the Tint to which ever color you want to.
or you can also do it programatically by using the below code
You can use
UIAppearance
protocol to apply changes for all text views:Swift 4.x:
Swift 3.x:
Swift 2.x:
Objective-C:
Appearance for
UITextView
is not documented, but works well.Keep in mind
UIAppearance
notes:In other words: Calling this code in
init()
, orinit(coder:)
methods will change UI Object appearance, but calling inloadView()
, orviewDidLoad()
of viewController won't.If you want to set appearance for whole application,
application(_:didFinishLaunchingWithOptions:)
is good place for calling such code.EDIT: Don't do it with
UITextView
, useUIWebView
instead.You need to make a stylesheet for that. Define a class there with the color combination you need-
now use the class 'headercopy' into you html page like this-
this will display the phone number in the color you need with click functionality.
On iOS 7 you can set the
tintColor
of theUITextView
. It affects the link color as well as the cursor line and the selected text color.iOS 7 also added a new property to
UITextView
calledlinkTextAttributes
which would appear to let you fully control the link style.