Simplifier
是流行的扩展包
要运行示例项目,请克隆仓库,并首先从示例目录运行pod install
。
Simplifier可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中:
pod "Simplifier"
组成字典
var dict = ["one":1]
dict += ["two":2] + ["three":3] //["two": 2, "one": 1, "three": 3]
使用圆角创建视图边框
myView.makeRoundBorder(ofColor: .black, width: 1, radius: 3)
向视图添加约束
myView.addConstaintsToSuperview(leftOffset: 0, topOffset: 0)
myView.addConstaints(height: 64, width: 64)
截取视图的截图
let screenshot:UIImage = myView.snapshotImage
如有必要,取导航控制器的内容控制器
let contentVC = destinationVC.contentViewController
使用单方法在当前日历中构建数据,并获取日期组件
let dt = Date.from(year: 2017, month: 6, day: 25, hour: 12)
dt.month // 6
dt.year // 2017
安全的集合下标 - 返回可选值
let optionalElement = array[safe: 15]
用圆角创建颜色UIImage
let image = UIImage.ofColor(.red, size: size, cornerRadius: 5)
创建渐变图像
let gradient = Gradient(direction:.leftRight, size:CGSize(width:50, height:10), startColor:.red, endColor:.yellow)
let gradientImage = UIImage.gradientImage(gradient)
使用半径对UIImage进行高斯模糊
let imageWithBlur = myImage.blurImage(radius: 8)
获取图像的像素颜色
let color = myImage.pixelColor(for: CGPoint(x:10, y:10))
将图像转换为单色模板
let maskedImage = myImage.maskWithColor(color: .blue)
裁剪图像为正方形
let cropped = myImage.squareCroppedImage()
缩放图像到大小
let resized = myImage.scaledTo(size:mySize)
获取俄文可数名词的正确结尾
for i in 1...7 {
print(String(i)+" "+String.russianWordFor(number: i, one: "яйцо", two: "яйца", five: "яиц"))
}
输出
1 яйцо
2 яйца
3 яйца
4 яйца
5 яиц
6 яиц
7 яиц
从字符串生成图像
let myImage = "STR".generateImage(of: CGSize(width:50,height:50), font: UIFont.systemFont(ofSize: 10), color: .red)
轻松创建NSAttributedString
let attrStr = NSAttributedString(string: "STR", font: font.withSize(10), color: .red)
Alex Shubin,互动服务,[email protected],[email protected]
Simplifier 可在 MIT 许可协议下使用。更多信息请参阅 LICENSE 文件。