Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.
/ ALayout Public archive

A Layout framework that helps Sketch users realize their design on iOS platform.

License

Notifications You must be signed in to change notification settings

EdgarDegas/ALayout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Layout framework that helps Sketch users realize their design on iOS platform.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published