To run the example project, clone the repo, and run pod install
from the Example directory first.
let textView = AttributedTextView()
let model = TextModel(id: "id-0", text:"hashtag", symbolStr: "#", image: nil, type: 0)
textView.insertSpecialText(model: model, isDeleteLastString: false)
textView.modelMapper = { text -> TextModel? in
let splits = text.split()
guard
splits.count >= 4,
let id = splits[safe: 1]?.description,
let type = splits[safe: 2]?.description.int,
let text = splits[safe: 3]?.description
else { return nil }
switch type {
case 0: return TextModel(id: id, text: text, symbolStr: "#", image: nil, type: type)
case 1: return TextModel(id: id, text: text, symbolStr: "@", image: nil, type: type)
default: return TextModel(id: id, text: text, symbolStr: nil, image: #imageLiteral(resourceName: "location"), type: type)
}
}
textView.set(text: text)
let label = AttributedLabel()
label.modelMapper = { text -> TextModel? in
let splits = text.split()
guard
splits.count >= 4,
let id = splits[safe: 1]?.description,
let type = splits[safe: 2]?.description.int,
let text = splits[safe: 3]?.description
else { return nil }
switch type {
case 0: return TextModel(id: id, text: text, symbolStr: "#", image: nil, type: type)
case 1: return TextModel(id: id, text: text, symbolStr: "@", image: nil, type: type)
default: return TextModel(id: id, text: text, symbolStr: nil, image: #imageLiteral(resourceName: "location"), type: type)
}
}
label.clickLink = { model in
guard let m = model else { return }
debugPrint(m.text)
}
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4
let defaultAttributes: [NSAttributedString.Key : Any] = [
.font: UIFont.systemFont(ofSize: 15),
.foregroundColor: UIColor.black,
.paragraphStyle: paragraphStyle,
]
let attr = NSAttributedString(string: text, attributes: defaultAttributes)
label.set(attributedString: attr)
AttributedText is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'AttributedText'
wave, [email protected]
AttributedText is available under the MIT license. See the LICENSE file for more info.