Giter VIP home page Giter VIP logo

swiftyimage's Introduction

SwiftyImage

Swift CocoaPods CI

The most sexy way to use images in Swift.

Features

At a Glance

Creating Images
UIImage.size(width: 100, height: 100)
  .color(.white)
  .border(color: .red)
  .border(width: 10)
  .corner(radius: 20)
  .image

sample1

UIImage.resizable()
  .color(.white)
  .border(color: .blue)
  .border(width: 5)
  .corner(radius: 10)
  .image

sample2

Creating Color Overlayed Image
let image = UIImage(named: "myArrow").with(color: UIColor.blueColor())

Getting Started

SwiftyImage provides a simple way to create images with method chaining.

Step 1. Start Chaining

Method chaining starts from UIImage.size() or UIImage.resizable().

UIImage.size(width: CGFloat, height: CGFloat) // ...
UIImage.size(size: CGSize) // ...
UIImage.resizable() // ...

Step 2. Setting Properties

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)

Step 3. Generating Image

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

Methods Available

Starting Method Chaining

  • .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

Setting Properties

  • .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

Generating Image

  • .image

    Generates and returns image

Play with CGContext

SwiftyImage also provides a simple method to create or manipulate images with CGContext.

Creating Images

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))
}

Manipulating Images

let newImage = oldImage.with { context in
  UIColor.lightGrayColor().setFill()
  CGContextFillEllipseInRect(context, CGRect(x: 0, y: 0, width: 100, height: 100))
}

Image Operator

You can easily combine multiple images with + operator.

let backgroundImage = ...
let iconImage = ...
let combinedImage = backgroundImage + iconImage

combine

Installation

pod 'SwiftyImage', '~> 1.1'

Playground

Use CocoaPods command $ pod try SwiftyImage to try Playground!

playground

License

SwiftyImage is under MIT license. See the LICENSE file for more info.

swiftyimage's People

Contributors

devxoul avatar murselturk avatar fuyoufang avatar

Stargazers

 avatar Anne Thorpe avatar 1024小神 avatar Christopher Grantham avatar 方同学 avatar Lobo avatar Nathan Fallet avatar imoreapps avatar  avatar  avatar Mikhail Chaus avatar  avatar Rakhim Abdullayev avatar  avatar  avatar Emre Balkay avatar  avatar Hieu Ngo avatar  avatar  avatar  avatar ClockHU avatar Subin Yoon avatar bingbing avatar HAN SHANTAO avatar  avatar 穆宁 avatar Рафаэль avatar Henry avatar  avatar beforeold avatar nisch.codes avatar  avatar quntion avatar houseme avatar sani avatar Feng,Chih Sheng avatar Jim Muir avatar mosken avatar Santiago Rodriguez Affonso avatar Ezequiel Alejandro Becerra avatar  avatar Soohyun Park avatar fred avatar Müge Çevik avatar  avatar Felix.Hu avatar LIMJISEONG avatar koi avatar limheechan avatar Hyungyu Kim avatar Jungbin Jung avatar Junyeong Hwang avatar Sunggweon Hyeong avatar Liu Rui avatar Huang Runhua avatar Mason Sun avatar  avatar Maxim Kolesnik avatar  avatar  avatar jingxuelong avatar Vatsal Kelawala avatar  avatar Toseef Khilji avatar Aleksandr Ponomarenko avatar Mark Villacampa avatar  avatar  avatar Dou.Z avatar Nando avatar Quanhai avatar H. Kürşat ŞİMŞEK avatar  avatar Catalin Miron avatar Kaaaaai avatar Tim Lehr avatar Jayson Rhynas avatar  avatar  avatar  avatar  avatar AxcLogo avatar AChao avatar Chun Ye avatar Vlad Likov avatar Ydna avatar 杨俊艺 avatar Jeff Andrews avatar  avatar Su Ho avatar Vinh Nguyen avatar ZhangWei avatar zly avatar  avatar  avatar  avatar  avatar gl avatar Charlie Liao avatar

Watchers

Andreas Kostuch avatar Emre Barack Sokullu avatar  avatar Muescha avatar HoNooD avatar James Cloos avatar  avatar MohsinAli avatar  avatar  avatar 王帅 avatar Yanis Salos avatar  avatar  avatar Donghoon Lee avatar  avatar  avatar Peter Salz avatar  avatar

swiftyimage's Issues

UIImage operator overload for addition result is incorrect

The resultant UIImage is upside down and backwards. This can be fixed if you replace:

CGContextDrawImage(context, lhsRect, lhs.CGImage)
CGContextDrawImage(context, rhsRect, rhs.CGImage)

with this:

lhs.drawInRect(lhsRect)
rhs.drawInRect(rhsRect)

Question to UIImage -> size

Hello,

could you please help me.
I get the following error:
let image1 = UIImage(named: "home")?.si(width: 106, height: 106)

bildschirmfoto 2018-02-21 um 19 04 02

Best regards
Frank

How would I adjust constraints when overlaying an image with another image?

The README shows how to overlay images (let newImage = image1 + image2). This shows how it would paste an image directly onto another image but how would I adjust the layout / constraints? (e.g. How would I add image 2 to the bottom left corner of image1?). Is this possible with SwiftyImage? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.