Swift最简单创建支持多个链接的UITextView属性方法

你有没有遇到过在 iOS 开发中,想在UITextView里放多个可点击的链接,却被系统默认的单一链接支持给限制住了的情况?其实,使用NSAttributedStringNSMutableAttributedString就可以这个问题,挺。,你需要创建一个自定义的UITextView子类,这样可以加上一些自己的逻辑,比如支持多个链接的点击。,用正则表达式来识别文本中的链接,并通过addAttribute方法给每个链接添加样式。,你只需要监听点击事件,判断用户是否点击了某个链接就好。这样一来,多个链接就都能在你的UITextView中生效了。别担心,代码也不复杂,一步步走下来,基本能做到。哦对了,如果你需要进一步美化富文本,比如改变链接的字体颜色、大小,NSAttributedString也能满足需求!

zip
swift-最简单的方法来创建一个属性的UITextView支持多个链接.zip 预估大小:53个文件
folder
evermeer-AttributedTextView-80a2ebd 文件夹
file
.gitignore 632B
folder
Screenshots 文件夹
file
Sample5.png 57KB
file
IconList.png 198KB
file
Sample1.png 18KB
file
Sample4.png 18KB
file
Sample3.png 16KB
file
Sample6.png 11KB
file
Sample2.png 18KB
folder
Sources 文件夹
file
CGFloatDP.swift 679B
file
String+Attributer.swift 21KB
file
Info.plist 753B
file
Attributer.swift 36KB
file
NSAttributedString+Html.swift 751B
file
String+NSRange.swift 366B
file
AttributedLabel.swift 1KB
file
AttributedTextView.swift 9KB
file
Info-tvOS.plist 838B
file
AttributedTextView.h 567B
folder
Cartfile.private 文件夹
file
.swiftlint.yml 801B
file
.travis.yml 3KB
folder
AttributedTextView.xcworkspace 文件夹
folder
xcshareddata 文件夹
file
IDEWorkspaceChecks.plist 238B
file
contents.xcworkspacedata 703B
file
LICENSE 1KB
folder
Demo 文件夹
file
ViewController.swift 8KB
file
check.png 4KB
file
Info.plist 1KB
folder
Base.lproj 文件夹
file
LaunchScreen.storyboard 2KB
file
Main.storyboard 8KB
file
cross.png 4KB
file
AttributedLabelSubclassDemo.swift 4KB
file
AttributedTextViewSubclassDemo.swift 1KB
file
warning.png 3KB
file
AppDelegate.swift 430B
folder
Assets.xcassets 文件夹
folder
AppIcon.appiconset 文件夹
file
Contents.json 1KB
folder
AttributedTextView.playground 文件夹
file
Contents.swift 6KB
folder
playground.xcworkspace 文件夹
folder
xcshareddata 文件夹
file
IDEWorkspaceChecks.plist 238B
file
contents.xcworkspacedata 135B
file
contents.xcplayground 184B
file
timeline.xctimeline 15KB
file
Readme.md 17KB
folder
scripts 文件夹
file
bootstrap 47B
folder
AttributedTextView.xcodeproj 文件夹
folder
xcshareddata 文件夹
folder
xcschemes 文件夹
file
AttributedTextView-iOS.xcscheme 4KB
file
AttributedTextView-tvOS.xcscheme 4KB
file
AttributedTextView-watchOS.xcscheme 3KB
file
AttributedTextView-macOS.xcscheme 4KB
folder
project.xcworkspace 文件夹
folder
xcshareddata 文件夹
file
IDEWorkspaceChecks.plist 238B
file
contents.xcworkspacedata 163B
file
project.pbxproj 42KB
file
Cartfile.resolved 62B
folder
Cartfile 文件夹
file
Package.swift 277B
file
AttributedTextView.podspec 776B
...
zip 文件大小:381.2KB