我有一個UITextView,其中包含大量帶有數字的文本。我試圖檢測文本視圖中的數字,但無法實現。我只能找到解決方案來找到鏈接。在UiTextView中插入一個數字並檢測數字
我正在使用NSAttributedString來顯示文本。
.dataDetectorTypes似乎不起作用。任何一個可以幫助我
我想這樣。
let middleTextView: UITextView = {
let tv = UITextView();
let attributedText = NSMutableAttributedString(string: "Your NetCode will be sent to", attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 14)]);
attributedText.append(NSAttributedString(string: "\n\nXXXX XXX 252", attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 16)]));
attributedText.append(NSMutableAttributedString(string: "\n\n To update you mobile number call tel://13 2221", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12)]));
// let url = NSURL(string: "tel://\(1234)");
// tv.text = url;
tv.attributedText = attributedText;
tv.textAlignment = .center
tv.backgroundColor = UIColor.clear;
tv.dataDetectorTypes = .phoneNumber;
tv.isEditable = false;
tv.isSelectable = false;
tv.translatesAutoresizingMaskIntoConstraints = false;
return tv;
}();
什麼是你想回去?電話號碼'13 2221'? –
是的,我想要13 2221被點擊,以便呼叫選項得到提示 – Bikram