UITextView如何实现只允许链接交互,不允许选择图片

大家都知道,UITextVview可以用以下方法自动检测text中的链接:
let label = UITextView()
label.dataDetectorTypes = .link
label.isEditable = false
如果我们使用的attributedString后,会发现如果添加Attachment后,会触发一个选择(编辑的GR),如果我们只想要链接的gr,不想要选择的gr,可以遍历并禁用它。方法如下:

传送门:http://stackoverflow.co[......]

继续阅读

UIButton设置按下背景色

http://stackoverflow.com/questions/14523348/how-to-change-the-background-color-of-a-uibutton-while-its-highlighted

UIButton只能设置按下的背景图片,所以我们可以曲线救国,将背景色转换为一张图片

Return an image made from the highlight colour you want. This could also be a category[......]

继续阅读

UITextView自动换行的解法

多行文本,如何让UITextView自动换行,且高度自适应
view.addSubview(textView)
let width = UIScreen.main.bounds.width - 40
let size = textView.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude))
textView.snp.makeC[......]

继续阅读