Jamel  O'Reilly

Jamel O'Reilly

1659504480

SwiftyLayout: Lightweight Declarative Auto-layout Framework for Swift

SwiftyLayout

SwiftyLayout is a framework that allows to describe layout constraints (ie NSLayoutConstraint) as a simple mathematical formula in a Swift program.

About Version

  • SwiftyLayout 3 for Swift 2
  • SwiftyLayout 4 for Swift 3

Code Examples

Basic usage

Using the framework, a layout constraint that "the width of the view A is equal to minus 4.0 to 50% of the width of the Views B" follows:

viewA[.Width] == 0.5 * viewB[.Width] - 4.0

This is the same layout constraints with the following code:

NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewB, attribute: .Width,
    multiplier: 0.5, constant: -4.0)

e.g. Aspect ratio

A layout constraint that "the aspect ratio of the view A is 3:4" follows:

viewA[.Width] * 3.0 == viewA[.Height] * 4.0

This is the same layout constraints with the following code:

NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewA, attribute: .Height,
    multiplier: 4.0/3.0, constant: 0.0)

e.g. Specify the priority

The framework has priority specification operator ~ like the following.

innerView[.Leading] == outerView[.Leading] + 4.0 ~ 750.0

This is the same layout constraints with the following code:

var constraint = NSLayoutConstraint(
    item: innerView, attribute: .Leading,
    relatedBy: .Equal,
    toItem: outerView, attribute: .Leading,
    multiplier: 1.0, constant: 4.0)
constraint.priority = 750.0
// -> constraint

Please refer to the code for the sample application and test case, too.

Refrence Guide

ConstraintTerm

ConstraintTerm means a term that contains a view in the right side or the left side of a layout constraint. For example, a ConstraintTerm representing the width .Width of view viewA:

viewA[.Width]

viewA is a UIView instance object, .Width is a NSLayoutAttribute value. ConstraintTerm is defined as a structure such as the following:

public struct ConstraintTerm
{
    let view: UIView?
    let attribute: NSLayoutAttribute
    var multiplier: CGFloat = 1.0
    var constant: CGFloat = 0.0
}

Operators

The following table, CONSTANT means CGFloat value

operatorlhsrhsvaluesemantics
+ConstraintTermCONSTANTConstraintTermadd rhs value to lhs.constant
+CONSTANTConstraintTermConstraintTermadd lhs value to rhs.constant
-ConstraintTermCONSTANTConstraintTermsubtract rhs value from lhs.constant
*ConstraintTermCONSTANTConstraintTermmultiply rhs value to lhs.multiplier and lhs.constant
*CONSTANTConstraintTermConstraintTermmultiply lhs value to rhs.multiplier and rhs.constant
/ConstraintTermCONSTANTConstraintTermdivide lhs.multiplier and lhs.constant by rhs value
==ConstraintTermConstraintTermNSLayoutConstraintcreate a layout constraint that "lhs is equal to lhs"
==ConstraintTermCONSTANTNSLayoutConstraintditto
==CONSTANTConstraintTermNSLayoutConstraintditto
<=ConstraintTermConstraintTermNSLayoutConstraintcreate a layout constraint that "lhs is less than or equal to lhs"
<=ConstraintTermCONSTANTNSLayoutConstraintditto
<=CONSTANTConstraintTermNSLayoutConstraintditto
>=ConstraintTermConstraintTermNSLayoutConstraintcreate a layout constraint that "lhs is greater than or equal to lhs"
>=ConstraintTermCONSTANTNSLayoutConstraintditto
>=CONSTANTConstraintTermNSLayoutConstraintditto
~NSLayoutConstraintCONSTANT(Float)NSLayoutConstraintChange the priority of a layout constraint, and return the constraint

Requirements

  • Swift 2.0 (Xcode 7 or later)
  • iOS
    • iOS 8 or later / iOS 7 (by coping the source files directly)
  • Mac
    • Mac OS X 10.10 or later

Installation

There are two options.

Using Carthage

Using Carthage, it's easy to add SwiftyLayout to the project.

  • Add github "fhisa/SwiftyLayout" to your Cartfile.
  • Run carthage update
  • Add SwiftyLayout.framework in Carthage/Build/iOS to your Xcode project.

Copying source files directly (iOS 7)

  • Add this repository as a git submodule:
$ git submodule add https://github.com/fhisa/SwiftyLayout.git PATH_TO_SUBMODULE
// or
$ carthage update --use-submodules
  • Then just add references of SwiftyLayout/*.swift to your Xcode project.

TODO

Author: fhisa
Source Code: https://github.com/fhisa/SwiftyLayout
License: MIT license

#ios #swift 

What is GEEK

Buddha Community

SwiftyLayout: Lightweight Declarative Auto-layout Framework for Swift
Houston  Sipes

Houston Sipes

1600430400

10 Free Online Resources To Learn Swift Language

Swift is a fast and efficient general-purpose programming language that provides real-time feedback and can be seamlessly incorporated into existing Objective-C code. This is why developers are able to write safer, more reliable code while saving time. It aims to be the best language that can be used for various purposes ranging from systems programming to mobile as well as desktop apps and scaling up to cloud services.

Below here, we list down the 10 best online resources to learn Swift language.

(The list is in no particular order)

#developers corner #free online resources to learn swift language #learn swift #learn swift free #learn swift online free #resources to learn swift #swift language #swift programming

Top Swift Development Companies | Top Swift Developers - TopDevelopers.co

A thoroughly researched list of top Swift developers with ratings & reviews to help find the best Swift development companies around the world.

#swift development service providers #best swift development companies #top swift development companies #swift development solutions #top swift developers #swift

Hire Dedicated Swift Developers

Want to create a native iOS application for your Startup?

Hire Dedicated Swift Developers for end-to-end services like development, migration, upgrade, testing, and support & maintenance. Trust HourlyDeveloper.io our Swift development team for iOS device apps that are high on performance and security.

Consult with experts:- https://bit.ly/2C5M6cz

#hire dedicated swift developers #swift developers #swift development company #swift development services #swift development #swift

Jamel  O'Reilly

Jamel O'Reilly

1659504480

SwiftyLayout: Lightweight Declarative Auto-layout Framework for Swift

SwiftyLayout

SwiftyLayout is a framework that allows to describe layout constraints (ie NSLayoutConstraint) as a simple mathematical formula in a Swift program.

About Version

  • SwiftyLayout 3 for Swift 2
  • SwiftyLayout 4 for Swift 3

Code Examples

Basic usage

Using the framework, a layout constraint that "the width of the view A is equal to minus 4.0 to 50% of the width of the Views B" follows:

viewA[.Width] == 0.5 * viewB[.Width] - 4.0

This is the same layout constraints with the following code:

NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewB, attribute: .Width,
    multiplier: 0.5, constant: -4.0)

e.g. Aspect ratio

A layout constraint that "the aspect ratio of the view A is 3:4" follows:

viewA[.Width] * 3.0 == viewA[.Height] * 4.0

This is the same layout constraints with the following code:

NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewA, attribute: .Height,
    multiplier: 4.0/3.0, constant: 0.0)

e.g. Specify the priority

The framework has priority specification operator ~ like the following.

innerView[.Leading] == outerView[.Leading] + 4.0 ~ 750.0

This is the same layout constraints with the following code:

var constraint = NSLayoutConstraint(
    item: innerView, attribute: .Leading,
    relatedBy: .Equal,
    toItem: outerView, attribute: .Leading,
    multiplier: 1.0, constant: 4.0)
constraint.priority = 750.0
// -> constraint

Please refer to the code for the sample application and test case, too.

Refrence Guide

ConstraintTerm

ConstraintTerm means a term that contains a view in the right side or the left side of a layout constraint. For example, a ConstraintTerm representing the width .Width of view viewA:

viewA[.Width]

viewA is a UIView instance object, .Width is a NSLayoutAttribute value. ConstraintTerm is defined as a structure such as the following:

public struct ConstraintTerm
{
    let view: UIView?
    let attribute: NSLayoutAttribute
    var multiplier: CGFloat = 1.0
    var constant: CGFloat = 0.0
}

Operators

The following table, CONSTANT means CGFloat value

operatorlhsrhsvaluesemantics
+ConstraintTermCONSTANTConstraintTermadd rhs value to lhs.constant
+CONSTANTConstraintTermConstraintTermadd lhs value to rhs.constant
-ConstraintTermCONSTANTConstraintTermsubtract rhs value from lhs.constant
*ConstraintTermCONSTANTConstraintTermmultiply rhs value to lhs.multiplier and lhs.constant
*CONSTANTConstraintTermConstraintTermmultiply lhs value to rhs.multiplier and rhs.constant
/ConstraintTermCONSTANTConstraintTermdivide lhs.multiplier and lhs.constant by rhs value
==ConstraintTermConstraintTermNSLayoutConstraintcreate a layout constraint that "lhs is equal to lhs"
==ConstraintTermCONSTANTNSLayoutConstraintditto
==CONSTANTConstraintTermNSLayoutConstraintditto
<=ConstraintTermConstraintTermNSLayoutConstraintcreate a layout constraint that "lhs is less than or equal to lhs"
<=ConstraintTermCONSTANTNSLayoutConstraintditto
<=CONSTANTConstraintTermNSLayoutConstraintditto
>=ConstraintTermConstraintTermNSLayoutConstraintcreate a layout constraint that "lhs is greater than or equal to lhs"
>=ConstraintTermCONSTANTNSLayoutConstraintditto
>=CONSTANTConstraintTermNSLayoutConstraintditto
~NSLayoutConstraintCONSTANT(Float)NSLayoutConstraintChange the priority of a layout constraint, and return the constraint

Requirements

  • Swift 2.0 (Xcode 7 or later)
  • iOS
    • iOS 8 or later / iOS 7 (by coping the source files directly)
  • Mac
    • Mac OS X 10.10 or later

Installation

There are two options.

Using Carthage

Using Carthage, it's easy to add SwiftyLayout to the project.

  • Add github "fhisa/SwiftyLayout" to your Cartfile.
  • Run carthage update
  • Add SwiftyLayout.framework in Carthage/Build/iOS to your Xcode project.

Copying source files directly (iOS 7)

  • Add this repository as a git submodule:
$ git submodule add https://github.com/fhisa/SwiftyLayout.git PATH_TO_SUBMODULE
// or
$ carthage update --use-submodules
  • Then just add references of SwiftyLayout/*.swift to your Xcode project.

TODO

Author: fhisa
Source Code: https://github.com/fhisa/SwiftyLayout
License: MIT license

#ios #swift 

Clemmie  Will

Clemmie Will

1598292780

Benchmark the performances of various Swift layout frameworks

Layout Framework Benchmark

Benchmark the performances of various Swift layout frameworks (autolayout, UIStackView, PinLayout, LayoutKit, FlexLayout, Yoga, …)

Requirements

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0+

History

This project is a spin-off of the excellent LayoutKit benchmark. The benchmark has been extracted to add other iOS layout frameworks and to compare them.

Why?

Choosing the right layout framework for your project is an important decision. The frameworks API is quite important, but its performance is also important. To help you with that decision, this benchmark compare different layout frameworks.

#layout #framework #swift