OptimalLabelTextSize
OptimalLabelTextSize 是一系列 @IBDesignable iOS 控件(标签、按钮),具有有用的 @IBInspectable 属性。它们允许您构建最佳字号文本字体,并在 Xcode Interface Builder 中直接查看结果。
使用 Swift 编写
如何使用
- 将控件(例如
UILabel
)添加到 Storyboard 中 - 将标签的类更改为
TextSizeDevice
。同时将模块更改为OptimalLabelTextSize
- 现在您可以直接从 IB 定制标签:
自定义标签有字段
1. Max Text Size : Int
Installing max valid text Size
Default value = 17
2. Min Text Size : Int
Installing min valid text Size
Default value = 17
3. Master Diagonal : CGFloat
We point to it relatively what divece settings text size
Permissible values :
"IPHONE XR" = 6,1
"IPHONE X, IPHONE XS" = 5,8
"IPHONE XS_MAX" = 6,5
"IPHONE 5, 5S, 5C, SE" = 4,0
"IPHONE 6,7,8 IPHONE 6S,7S,8S " = 4,7
"IPHONE 6PLUS, 6SPLUS, 7PLUS, 8PLUS" = 5,5
"iPad 5th Generation, iPad Retina, iPad Air, iPad Pro 9.7" = 9,7
IPHONE 4,4S = 3,5
"iPad Pro 10.5" = 10,5
"iPad Pro 12.9" = 12,9
"iPad Mini 7,9" =7,9
.uknown iPhone:
return 4.7
.uknown iPad:
return 10.5
Default value = 6,1
4. Auto Min Height : Bool
value true =
set minHeight = 9.0
set maxHeight = currentTextSize + 3
Default value = false
5. is Show Text Size: Bool
value true =
set .text = FontName + TextSize
Default value = false
6. StrengthenK : CGFloat
value > 1 Reinforcing degree optimize
value < 1 Reduces degree optimize
value = 1 Non - affecting optimize
Default value = 1,0
程序化地优化标签或按钮
import OptimalLabelTextSize
let k = DeviceDiagonal.getDiagonal() / DeviceSize.XR_6_1.inch TextSizeDevice.setTextSize(with: k, currentSize: 19.0, strengthenK: 1.0, maxTextSize: 19, minTextSize: 14, label: Button.titleLabel!)
要求
- Xcode 6 或更高版本
- iOS 8 或更高版本
- Swift 4.2 或更高版本
安装
OptimalLabelTextSize 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中:
pod 'OptimalLabelTextSize'
作者
snazarovone,[email protected]
许可证
OptimalLabelTextSize 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。