🥕
Nantes
这个库是objective-c知名库TTTAttributedLabel的Swift版本。很多
Nantes
是一个纯 Swift 的 UILabel
替代品。它支持属性、数据检测等功能,还可以自动支持链接嵌入和 NSTextCheckingTypes
。
加入我们,一起在Instacart中打造精彩事物!
要求
- iOS 8.0+
- Swift 4.2
安装
Nantes 通过Carthage提供。要安装它,请将以下行添加到您的 Cartfile
github "instacart/nantes"
CocoaPods
Nantes 通过CocoaPods提供。要安装它,只需将以下行添加到您的 Podfile
pod 'Nantes'
通信
如果您需要帮助,请随意打开一个issue。在打开之前先进行搜索,可能有人曾经遇到过类似的问题。
贡献
提交一个pull request是最好的修复问题的方法。如果您需要帮助,请随意打开一个issue,希望有人可以帮助您解决遇到的问题。
作者
chansen22, [email protected]
示例
要运行示例项目,首先克隆仓库,然后在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.