这个库是流行的 Objective-C 库 TTTAttributedLabel 的 Swift 移植/分支。 非常感谢 Mattt 创建了如此出色的 UILabel 替代库,并致以衷心的感谢 ❤️。
Nantes
是一个纯 Swift 的 UILabel
替代品。 它支持属性、数据检测器等等。 它还支持自动和使用 NSTextCheckingTypes
进行链接嵌入。
来 Instacart! 和我们一起构建令人惊叹的东西吧!
Nantes 可以通过 Carthage 获得。 要安装它,请将以下行添加到您的 Cartfile
中
github "instacart/nantes"
Nantes 可以通过 CocoaPods 获得。 要安装它,只需将以下行添加到您的 Podfile 中
pod 'Nantes'
如果您需要帮助,请随时提出 issue。 在提出问题之前请先搜索,可能已经有人遇到过类似的问题。
提出 pull request 是解决问题的最佳方法。 如果您需要帮助,请随时提出 issue,希望有人可以帮助您解决您遇到的问题。
chansen22, cthansen22@gmail.com
要运行示例项目,请克隆存储库,然后首先从 Example 目录运行 pod install
。
在 Example
目录中查看 Nantes
以获取更多示例。
import Nantes
let label: NantesLabel = .init(frame: .zero)
label.attributedTruncationToken = NSAttributedString(string: "... more")
label.numberOfLines = 3
label.labelTappedBlock = {
label.numberOfLines = label.numberOfLines == 0 ? 3 : 0 // Flip between limiting lines and not
UIView.animateWithDuration(0.2, animations: {
self.view.layoutIfNeeded()
})
}
label.text = "Nantes label is great! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ac urna et ante lobortis varius. Nunc rhoncus enim vitae sem commodo sodales. Morbi id augue id augue finibus tincidunt. Cras ac massa nisi. Maecenas elementum vitae elit eu mattis. Duis pretium turpis ut justo accumsan molestie. Mauris elit elit, maximus eu risus sed, vestibulum sodales enim. Sed porttitor vestibulum tincidunt. Maecenas mollis tortor quam, sed porta justo rhoncus id. Phasellus vitae augue tempor, luctus metus sit amet, dictum urna. Morbi sit amet feugiat purus. Proin vitae finibus lectus, eu gravida erat."
view.addSubview(label)
let linkLabel: NantesLabel = .init(frame: .zero)
linkLabel.delegate = self // NantesLabelDelegate
linkLabel.linkAttributes = [NSAttributedString.Key.foregroundColor: UIColor.green]
linkLabel.text = "https://www.instacart.com"
view.addSubview(linkLabel)
// Link handling
func attributedLabel(_ label: NantesLabel, didSelectLink link: URL) {
print("Tapped link: \(link)")
}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.