简化器 0.1.3

简化器 0.1.3

测试测试
语言语言 SwiftSwift
许可证 MIT
发布日期最新发布2017年6月
SwiftSwift版本3.1
SPM支持SPM

互动服务维护。



简化器 0.1.3

Simplifier 是流行的扩展包

示例

要运行示例项目,请克隆仓库,并首先从示例目录运行pod install

安装

Simplifier可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中:

pod "Simplifier"

用法

字典

组成字典

var dict = ["one":1]
dict += ["two":2] + ["three":3] //["two": 2, "one": 1, "three": 3]

UIView

使用圆角创建视图边框

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

UIViewController

如有必要,取导航控制器的内容控制器

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

用圆角创建颜色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

轻松创建NSAttributedString

let attrStr = NSAttributedString(string: "STR", font: font.withSize(10), color: .red)

作者

Alex Shubin,互动服务,[email protected][email protected]

许可协议

Simplifier 可在 MIT 许可协议下使用。更多信息请参阅 LICENSE 文件。