🖍 TypedTextAttributes
使用类型安全创建文本属性的库
这将对创建 NSAttributedString 有帮助。
使用方法
这是非常简单的示例代码。
let attributedString = "Hello".attributed {
TextAttributes()
.font(UIFont.preferredFont(forTextStyle: .headline))
.foregroundColor(.white)
.alignment(.right)
}
我们可以通过方法链创建文本属性。这些方法是通过为 Dictionary<NSAttributedString.Key, Any>
定义的扩展来定义的,所以我们也可以描述以下内容。
let baseAttributes = [NSAttributedString.Key : Any]()
let attributes = baseAttributes
.foregroundColor(.white)
.alignment(.right)
此外,[NSAttributedString.Key : Any]
在这个库中有别名 TextAttributes
。
添加属性的方法
- 字体
- 文字颜色
- 背景颜色
- 下划线样式
- 下划线颜色
- 删除线样式
- 删除线颜色
- 描边颜色
- 描边宽度
- 文字效果
- 链接
- 基线偏移
- 倾斜度
- 扩展
- 垂直字符形式
- 字距
- 段落样式
- 对齐方式
- 首行首缩进
- 首缩进
- 尾缩进
- 行高倍数
- 最大行高
- 行间距
- 段落间距
- 段前间距
- 断行模式
- 连字
- 附件
- 阴影
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令进行安装
$ gem install cocoapods
要使用 CocoaPods 将 TypedTextAttributes 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
target 'YourApp' do
pod 'TypedTextAttributes'
end
然后,运行以下命令
$ pod install
Carthage
Carthage 是一个去中心化的依赖管理器,它构建您的依赖项并提供二进制框架。
您可以使用以下命令,通过 Homebrew 安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 TypedTextAttributes 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "muukii/TypedTextAttributes"
运行 carthage update
构建框架,并将构建好的 TypedTextAttributes.framework
拖拽到您的 Xcode 项目中。
作者
muukii, [email protected]
许可证
TypedTextAttributes 适用于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。