EXTENSION
public extension UIImage
var isSquare: Bool
Is square aspect ratio
var sizeOnDisk: String
Size in KB or MB
var heightForScreenWidth: CGFloat
Height for screen width
var orientationFixed: UIImage
Correct the direction of the picture so that it positioned correctly
- Returns: Image
convenience init?(qrCodeFrom string: String)
Create QR code from string
- Parameter string: String for QR code
Name | Description |
---|---|
string | String for QR code |
static func withStarShape(size: CGSize, strokeColor: UIColor = .clear, lineWidth: CGFloat = 2.0, fillColor: UIColor?) -> UIImage?
Draw a star
- Parameters:
- size: Size
- strokeColor: Stroke color
- lineWidth: Line width
- fillColor: Fill color
- Returns: Drawn star as UIImage
Name | Description |
---|---|
size | Size |
strokeColor | Stroke color |
lineWidth | Line width |
fillColor | Fill color |
func withTintColor(_ color: UIColor) -> UIImage?
Returns an identical image with specified tint color. Note that the returned image is with rendering mode .alwaysOriginal
-
Reference
https://stackoverflow.com/questions/31803157/how-can-i-color-a-uiimage-in-swift
-
Parameter color: The tint color
-
Returns: An identical image with specified tint color
Name | Description |
---|---|
color | The tint color |
func aspectHeight(for width: CGFloat) -> CGFloat
Scale the height of the given width proportionally
-
parameter width: width
-
returns: New height
Name | Description |
---|---|
width | width |
func aspectWidth(for height: CGFloat) -> CGFloat
Scale the width of the given height proportionally
-
parameter height: Height
-
returns: New width
Name | Description |
---|---|
height | Height |
func aspectFitSize(forBindingSize binding: CGSize) -> CGSize
Keep the aspect ratio and return the fitting size of the given size
- Parameter binding: Size
- Returns: New size
Name | Description |
---|---|
binding | Size |
class func image(withPureColor color: UIColor, for rect: CGRect, rounded: Bool) -> UIImage?
Get an single-colored image
- Parameters:
- color: The color
- rect: The rect to draw in a CGContext.
- Returns: An single-colored image object, nil if any problems occur, such as CGRect.zero got passed.
Name | Description |
---|---|
color | The color |
rect | The rect to draw in a CGContext. |
func subImage(in rect: CGRect) -> UIImage?
Get certain part of image
- Parameter rect: Part of the image
- Returns: Image
Name | Description |
---|---|
rect | Part of the image |
func resized(to size: CGSize) -> UIImage?
Redraw the image to the specified size
- Parameter size: Size
- Returns: Image
Name | Description |
---|---|
size | Size |
func resizedImageWithAspectFitSize(forBindingSize binding: CGSize) -> UIImage?
func square() -> UIImage?
Resize the image so that its width and height are equal.
- Returns: A newly created image.
func with(backgroundColor: UIColor, cornerRadius: CGFloat, insets: UIEdgeInsets) -> UIImage?
Redraw a new image with the given requirements.
- Parameters:
- backgroundColor: The background color of the image.
- cornerRadius: The corner radius of the image, pass 0.0 if you perfer a squared one.
- insets: The inset to apply to the image.
- Returns: A newly created image.
Name | Description |
---|---|
backgroundColor | The background color of the image. |
cornerRadius | The corner radius of the image, pass 0.0 if you perfer a squared one. |
insets | The inset to apply to the image. |
static func arrowHead(direction: ArrowDirection, color: UIColor, size: CGSize, lineWidth: CGFloat = 2.0) -> UIImage?
class func borderImage(size: CGSize, backgroundColor: UIColor, borderColor: UIColor, borderWidth: CGFloat, cornerRadius: CGFloat) -> UIImage?
Draw a image with a border
- Parameters:
- size: size
- backgroundColor: color
- borderColor: border color
- borderWidth: border width
- cornerRadius: radius
- Returns: New image
Name | Description |
---|---|
size | size |
backgroundColor | color |
borderColor | border color |
borderWidth | border width |
cornerRadius | radius |
class func buttonBackgroundBorderImage(backgroundColor: UIColor, borderColor: UIColor, borderWidth: CGFloat, cornerRadius: CGFloat) -> UIImage?
Draw background image
- Parameters:
- backgroundColor: color
- borderColor: border color
- borderWidth: width
- cornerRadius: radius
- Returns: New image
Name | Description |
---|---|
backgroundColor | color |
borderColor | border color |
borderWidth | width |
cornerRadius | radius |