|
1 год назад | |
---|---|---|
.. | ||
Sources | 1 год назад | |
LICENSE | 1 год назад | |
README.md | 1 год назад |
The most sexy way to use images in Swift.
+
operatorUIImage.size(width: 100, height: 100)
.color(.white)
.border(color: .red)
.border(width: 10)
.corner(radius: 20)
.image
UIImage.resizable()
.color(.white)
.border(color: .blue)
.border(width: 5)
.corner(radius: 10)
.image
let image = UIImage(named: "myArrow").with(color: UIColor.blueColor())
SwiftyImage provides a simple way to create images with method chaining.
Method chaining starts from UIImage.size()
or UIImage.resizable()
.
UIImage.size(width: CGFloat, height: CGFloat) // ...
UIImage.size(size: CGSize) // ...
UIImage.resizable() // ...
You can set fill color, border attributes, corner radius, etc.
UIImage.size(width: 100, height: 100) // fixed size
.color(.white) // fill color
.border(color: .red) // border color
.border(width: 10) // border width
.corner(radius: 20) // corner radius
UIImage.resizable() // resizable image
.color(.white)
.border(color: .lightGray)
.border(width: 1)
.corner(radius: 5)
Use .image
at the end of method chaining to generate image.
imageView.image = UIImage.size(width: 100, height: 100)
.color(.white)
.border(color: .red)
.border(width: 10)
.corner(radius: 20)
.image // generate UIImage
.size(width: CGFloat, height: CGFloat)
Starts chaining for fixed size image
.size(CGSize)
Starts chaining for fixed size image
.resizable()
Starts chaining for resizable image
.color(UIColor)
Sets fill color
.color(gradient: [UIColor], locations: [CGFloat], from: CGPoint, to: CGPoint)
Sets gradient fill color
New in version 1.1.0
.border(width: CGFloat)
Sets border width
.border(color: UIColor)
Sets border color
.border(gradient: [UIColor], locations: [CGFloat], from: CGPoint, to: CGPoint)
Sets gradient border color
New in version 1.1.0
.border(alignment: BorderAlignment)
Sets border alignment. Same with Photoshop's
available values: .inside
, .center
, .outside
.corner(radius: CGFloat)
Sets all corners radius of image
.corner(topLeft: CGFloat)
Sets top left corner radius of image
.corner(topRight: CGFloat)
Sets top right corner radius of image
.corner(bottomLeft: CGFloat)
Sets bottom left corner radius of image
.corner(bottomRight: CGFloat)
Sets bottom right corner radius of image
.image
Generates and returns image
SwiftyImage also provides a simple method to create or manipulate images with CGContext.
let image = UIImage.with(size: CGSize(width: 100, height: 100)) { context in
UIColor.lightGrayColor().setFill()
CGContextFillEllipseInRect(context, CGRect(x: 0, y: 0, width: 100, height: 100))
}
let newImage = oldImage.with { context in
UIColor.lightGrayColor().setFill()
CGContextFillEllipseInRect(context, CGRect(x: 0, y: 0, width: 100, height: 100))
}
You can easily combine multiple images with +
operator.
let backgroundImage = ...
let iconImage = ...
let combinedImage = backgroundImage + iconImage
pod 'SwiftyImage', '~> 1.1'
Use CocoaPods command $ pod try SwiftyImage
to try Playground!
SwiftyImage is under MIT license. See the LICENSE file for more info.