YJExtensions
YJExtensions 常用扩展集合
Adding YJSwiftExtensions to your project (添加 YJSwiftExtensions 到你的项目)
CocoaPods
- Add a pod entry for
YJSwiftExtensions
to your Podfile
pod 'YJSwiftExtensions'
- Install the pod(s) by running
pod install
- Include
YJSwiftExtensions
wherever you need it with
import YJSwiftExtensions
Carthage
- Add YJSwiftExtensions to your Cartfile.
github "YJManager/YJSwiftExtensions"
- Run
carthage update
- Follow the rest of the standard Carthage installation instructions to add YJSwiftExtensions to your project.
Example举例:
由颜色生成图片
/// 颜色生成图片
public static func yj_createImage(_ color: UIColor) -> UIImage? {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image ?? nil
}