Code Monkey home page Code Monkey logo

alayout's Introduction

ALayout

Carthage compatible Build Status

A dynamic framework that allows you to easily add shadows to a UIView instance, using the same shadow paramters in Sketch.

This framework even supports animations on showing / hiding or changing the shadow.

This project is on a unstable beta stage. Think twice before using it on a business project.

Compatible with Swift 4.2 + and iOS 12.0 +.

ezgif.com-gif-maker


Getting Started

Prerequisites

Make sure you have Carthage installed. Otherwise, simply install with Homebrew:

brew install carthage


Include it to your iOS Project

  1. At the directory of your .xcodeproj or .xcworkspace file, create a file named Cartfile. Open the file using your text editor, add one line:
github "EdgarDegas/ALayout"
  1. At the same directory, execute this line into your Terminal:
carthage update
  1. When update is done, a new folder Carthage is created.

    1. Go to your target's general setting page: Linked Framework and Libraries
    2. Click +, select ใ€ŒAdd other...ใ€, then go into Carthage/Build/iOS, find ALayout.framework and add it.
  2. You need to add Run Script to at your build phases:

    Build Phases

    Make sure the path in the Input Files section is correct.



Quick tutorial

Add Shadows to UIView

  1. Import ALayout
import ALayout

  1. Initialize a Shadow object:
Shadow(color:opacity:Offset:blur:spread:)

The parameters are basically the same with those in Sketch. In case you are not familiar with UI design:

  • color: ShadowColor, UIColoris OK. Or you can use ShadowRGBAColor, ShadowHexColor` for convenience color setup.
  • opacity: CGFloat, ranging from 0.0 (transparent) to 1.0 (opaque)
  • offset, a tuple containing two CGFloat values:
    • dx: CGFloat, offset on x-axis, negative (leftward) or positive (rightward)
    • dy: CGFloat, offset on x-axis, negative (upward) or positive (downward)
  • blur: CGFloat, the blur radius of shadow, positive value
  • spread: CGFloat, increase or decrese the size of shadow from the size of your view

Initializing example:

let myShadow = Shadow(color: UIColor.black, opacity: 1, offset: (dx: 0, dy: 0), blur: 24)

  1. Set shadow:
myView.set(shadow: myShadow, animated: true)

And if you set a different Shadow instance now, you would see the shadow changing animation.

myView.set(shadow: anotherShadow, aniamted: true)

Somtimes you may need to specify clipsToBounds to false:

myView.clipsToBounds = false

  1. Remove shadow:
myView.removeShadow(animated: true)

  1. If your user interface needs layout, you should call this method at a proper timing:
myView.layoutShadow()

Under the Hood

By calling set(shadow:) on UIView instances, the framework inserts a CALayer with shadow at the bottom of the sublayers of the view's layer.

alayout's People

Contributors

edgardegas avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.