die*_*ego 2 xcode textview nsattributedstring swift swift4
我有 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;
}}
Run Code Online (Sandbox Code Playgroud)
但此代码显示此
所以我试图通过添加两行代码来解决这个问题:
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
] ;
Run Code Online (Sandbox Code Playgroud)
不幸的是,显示器不是我想要的。
有人帮助我解决这个问题,我在互联网上搜索但一无所获。
提前致谢
信息:我为本出版物拍摄的第一张图片:UITextView 中的链接在 Swift 4 中不起作用
| 归档时间: |
|
| 查看次数: |
457 次 |
| 最近记录: |