DevtorExtension
示例
要运行示例项目,请首先从仓库克隆项目,然后在 Example 目录下运行 pod install
。
用法
UIImageView
圆形 imageView
imageView.circleImageView(borderColor: .black, borderWidth: 1)
从 URL 下载图片
无缓存(默认)
imageView.downloaded(from: "https://example.com/image", contentMode: .scaleToFill)
带缓存
imageView.downloaded(from: "https://example.com/image", contentMode: .scaleToFill, cache: true)
UIImage
Base 64
从Base 64设置图像
imageView.imageFromBase64(base64: base64_string)
从图像(JPEG)获取Base 64字符串
imageView.image.base64(format: .jpeg(100), completion: { base64 in
print("Your base64 string is \(base64)")
})
从图像(PNG)获取Base 64字符串
imageView.image.base64(format: .png, completion: { base64 in
print("Your base64 string is \(base64)")
})
或者不完成
imageView.image.convertImageTobase64(format: .jpeg(100))
imageView.image.convertImageTobase64(format: .png)
图像缩放
按百分比
imageView.image.resizeWithPercent(percentage: 50)
按宽度
imageView.image.resizeWithWidth(width: 120)
缩放图像到新大小
imageView.image.scaleImageToSize(width: 800, height: 400)
图像缩放
按百分比
let newImage = imageView.image.imageWithColor(color: .black)
UIColor
您可以使用Material Colors, Metro Colors, Flat Colors, Social Colors(Facebook, LINE等)
非常简单的方式!您可以访问MaterialUI获取参考。
示例
let colorGreen = UIColor.Material.Green.primary
从十六进制获取颜色
UIColor(netHex: 0xffa140)
设置颜色更暗
color.darker(by: 30)
设置颜色更亮
color.lighter(by: 30)
从图像取色
image.averageColor()
字符串
数据验证
泰国公民身份证
string.verifyCitizenID()
手机号码
此功能将检查此号码是否有效,并返回泰国手机号码验证结果。
泰国手机号码:06,08,09 泰国电话号码:02,03,04,05,07
string.verifyMobileNumber()
字母数字验证(数字和字母组合)
string.isAlphanumeric()
数字验证
string.isNumber()
转换为格式
泰国公民ID
x-xxxx-xxxxx-xx-x
string.toCitizenIDFormat()
具有安全格式的公民ID
0-0000-xxxxx-xx-0
string.hideCitizenID()
您还可以自定义对话框,例如使用您的字符。
默认为 "-"
string.hideCitizenID(character: "-")
手机号码
xxx-xxx-xxxx
string.toMobileNumberFormat()
您还可以自定义对话框,例如使用您的字符。
默认为 "-"
string.toMobileNumberFormat(character: "-")
具有安全格式的手机号码
000 xxx xx00
string.hideMobileNumber()
您还可以自定义对话框,例如使用您的字符。
默认为 "-"
string.hideMobileNumber(character: "-")
护照安全格式
10位数字:yy-xxxxxxx 9位数字:yx-xxxxxx 8位数字:yx-xxxxx 7位数字:xx-xxxx
string.hidePassport()
Paperang MAC地址
此功能仅支持Paperang打印机。XX:XX:XX:XX:XX:XX
string.toPaperangMacAddressFormat()
二维码
string.toQRCode()
条码(Code128)
string.toBarcode()
导航控制器
删除虚线
NavigationController.removeHairLine()
添加图片
NavigationController.addImageToNavigationBar(titleImage: UIImage())
要求
- iOS 10.0+
- Swift 4.0+
安装
DevtorExtension 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'DevtorExtension'
作者
Feem.io
许可证
DevtorExtension 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。