【发布时间】:2018-04-03 20:39:17
【问题描述】:
NSAttributedStringKey 和 UITextView 有问题
事实上,我正在尝试这样做:
这是理论上应该可以工作的代码
class ViewController: UIViewController,UITextViewDelegate {
@IBOutlet weak var txtView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
txtView.delegate = self;
let linkAttributes : [NSAttributedStringKey : Any] = [
.link: URL(string: "https://exemple.com")!,
.font:UIFont.boldSystemFont(ofSize: 18),
.foregroundColor: UIColor.blue] ;
let attributedString = NSMutableAttributedString(string: "Just
click here to do stuff...")
attributedString.setAttributes(linkAttributes, range:
NSMakeRange(5, 10))
txtView.attributedText = attributedString;
}}
但是这段代码显示了这个
所以我尝试通过添加两行额外的代码来解决问题:
let linkAttributes : [NSAttributedStringKey : Any] = [
.link: URL(string: "https://exemple.com")!,
.font:UIFont.boldSystemFont(ofSize: 18),
.foregroundColor: UIColor.blue,
.strokeColor : UIColor.black,//new line
.strokeWidth : -1,//new line
] ;
不幸的是,显示不是我想要的。
有人帮我解决这个问题,我搜索了互联网但一无所获。
提前致谢
INFO:我为该出版物拍摄的第一张图片 :Link in UITextView not working in Swift 4
【问题讨论】:
标签: swift xcode textview swift4 nsattributedstring