I have a requirement to display the numbers as clickable link from a string input(contains alphabets and numerals) and on tap of that number it should open an iOS call dialler and should dials that number.
Below is what I have tried at the moment, to make the number to look like a tappable one and rest all text as normal default text with black color below formattedText var has been defined,
var formattedText: NSAttributedString{
let message = "Hey you can dial up {88 22 333} number for further assistance"
let linkRange = (message as NSString).range(of: fetchNumber) //fetchNumber method returns the content residing inside flower braces..
guard linkRange.location != NSNotFound else {return nil}
let finalString = NSMutableAttributedString(string: message, attributes:[.font: UIFont.scaledFont(from: .baseText16), foregroundColor: .black])
finalString.addAttributes([.foregroundColor: .blue], range: linkRange)
return finalString
}
output of above function is: Hey you can dial up 88 22 333
number for further assistance
and to make the number tappable I have tried using this attributed text input to UITextView with dataDetectorType property enabled but it is not working for me :( Is there any way to make it happen with UILabel itself or any sort of UIKit elements, any suggestions is much appreciated in advance, thanks
I have tried using this attributed text input to UITextView with dataDetectorType property enabled but it is not working for me :( Is there any way to make it happen with UILabel itself or any sort of UIKit elements, any suggestions is much appreciated in advance, thanks