文档章节

Manuscript

hejunbinlan
 hejunbinlan
发布于 2015/06/01 10:20
字数 628
阅读 9
收藏 0

It's like AutoLayoutKit but written in Swift. For pure Swift projects. And it's super simple.

Features

  •  concise, simple and convenient API

  •  raw AutoLayout power

  •  no black magic involved

  •  fully documented

  •  completely unit-tested

Have a look at the Changelog for more details.

Requirements

  • iOS 8.0+

  • Xcode 6.3

What it looks like

Manuscript.layout(myButton) { c in   c.set(.Height, to: 60.0)   c.set(.Width, to: 60.0)   c.make(.Bottom, equalTo: self.view, s: .Bottom, minus: 10.0)   c.make(.CenterX, equalTo: self.view, s: .CenterX) }

Usage

A few examples on how to use Manuscript.

Center and set size

Center a UIView 'childView' in self.view and make it 30 by 30 in size

Manuscript.layout(childView) { c in   c.make(.CenterX, equalTo: self.view, s: .CenterX)   c.make(.CenterY, equalTo: self.view, s: .CenterY)   c.set(.Width, to: 30.0)   c.set(.Height, to: 30.0) }

The same, but using the convenience methods

Manuscript.layout(childView) { c in   c.centerIn(self.view)   c.setSize(CGSize(width: 30.0, height: 30.0)) }

Align all edges of a view to a superview

Align a UIView 'container' to all edges of self.view

Manuscript.layout(container) { c in   c.make(.Left, equalTo: self.view, s: .Left)   c.make(.Right, equalTo: self.view, s: .Right)   c.make(.Top, equalTo: self.view, s: .Top)   c.make(.Bottom, equalTo: self.view, s: .Bottom) }

The same, but using the convenience methods

Manuscript.layout(container) { c in   c.alignAllEdges(to: self.view) }

Align all sides with insets

Align a UIView 'container' to all edges of self.view and leave a 30 point margin around the container.

Manuscript.layout(container) { c in   c.make(.Left, equalTo: self.view, s: .Left, plus: 30.0)   c.make(.Right, equalTo: self.view, s: .Right, minus: 30.0)   c.make(.Top, equalTo: self.view, s: .Top, plus: 30.0)   c.make(.Bottom, equalTo: self.view, s: .Bottom, minus: 30.0) }

The same, but using convenience methods.

Manuscript.layout(container) { c in   c.alignAllEdges(to: self.view, withInsets: UIEdgeInsets(top: 30.0, left: 30.0, bottom: 30.0, right: 30.0)) }

Use LayoutGuides

Make use of the LayoutGuides provided by UIViewController.

Manuscript.layout(container) { c in   c.make(.Left, equalTo: self.view, s: .Left)   c.make(.Right, equalTo: self.view, s: .Right)   c.make(.Top, equalTo: self.topLayoutGuide, s: .Baseline)   c.make(.Bottom, equalTo: self.bottomLayoutGuide, s: .Baseline) }

Hairlines

There is a utility method to create hairlines which takes the screen scale into account.

Manuscript.layout(mySeparatorLine) { c in   c.make(.Left, equalTo: self.view, s: .Left)   c.make(.Right, equalTo: self.view, s: .Right)   c.make(.Top, equalTo: self.topLayoutGuide, s: .Baseline)   // sets the .Height to 1.0 on non-retina displays and to 0.5 on retina displays   c.makeHorizontalHairline() }

Work with the created Layout Constraints

The functions make and set return a tuple of type LayoutItem which translates to (constraint: NSLayoutConstraint?, targetItem: UIView?). The 'constraint' is the created NSLayoutConstraint, the 'targetItem' is the view to which the NSLayoutConstraint was added. It is the nearest common superview of the UIViews involved.

Manuscript.layout(container) { c in   self.leftConstaint = c.make(.Left, equalTo: self.view, s: .Left).constraint   self.rightConstaint = c.make(.Right, equalTo: self.view, s: .Right).constraint   self.topConstaint = c.make(.Top, equalTo: self.topLayoutGuide, s: .Baseline).constraint   self.bottomConstaint = c.make(.Bottom, equalTo: self.bottomLayoutGuide, s: .Baseline).constraint }

Afterwards, just modify the constraint's constant and apply the changes (this is plain AutoLayout).

UIView.animateWithDuration(0.6) { in   self.topConstraint?.constant = 100   self.view.layoutIfNeeded() }

Convenience Methods

The convenience methods return arrays of the mentioned tuples. These will be dictionaries or tuples in the future as well to provide easier access to the created constraints. Until then, check the code for the order of the returned constraints.

Installation

As for now, you can use Carthage or Cocoapods to install Manuscript using a dependency manager or do it manually.

Carthage

To integrate Manuscript into your Xcode project using Carthage, specify it in your Cartfile:

github "floriankrueger/Manuscript"

Cocoapods

Make sure your Podfile contains all of the following lines.

use_frameworks! platform :ios, '8.0' pod 'Manuscript'

Then run pod install.

Manually

To do it 'by hand' take the following files and add them to your project:

  • Source/Manuscript.swift

  • Source/LayoutProxy.swift

License

Manuscript is released under the MIT License.


本文转载自:https://github.com/floriankrueger/Manuscript

上一篇: JSQWebViewController
下一篇: iOS多线程的创建
hejunbinlan
粉丝 42
博文 596
码字总数 21569
作品 0
浦东
高级程序员
私信 提问
Manuscript

Manuscript 是一款用 Swift 写成的 AutoLayoutKit 。 要求: iOS 8.0+ Xcode 6.3 概貌: Manuscript.layout(myButton) { c in c.set(.Height, to: 60.0) c.set(.Width, to: 60.0) c.make(.Bo......

sikkx
2015/05/29
160
0
生物信息学图数据库--Bio4j

Bio4j是一个基于生物信息学图的数据库,包括UniProt KB(SwissProt+ Trembl),基因本体论(GO)的,UniRef(50,90,100)的RefSeq,和NCBI分类中的大多数数据。 (准备稿)。 Bio4j is a bio...

匿名
2011/12/09
795
0
GIS及其相关期刊介绍

A list of relevant GIS journals We are curating a list of journals that we consider when submitting a GIS manuscript. Some of the journals listed below are not squarely GIS jour......

geowangsh
2016/02/03
31
0
2018年全球光信息与网络会议

Global Optical Information and Network Conference (GoInc) 2018 21-24 May 2018 Beijing Etrong International Exhibition and Convention Center, Beijing China Sponsors: Chinese Soci......

蟠桃会会议平台
2018/04/24
2
0
2018年全球光信息与网络会议

Global Optical Information and Network Conference (GoInc) 2018 21-24 May 2018 Beijing Etrong International Exhibition and Convention Center, Beijing China Sponsors: Chinese Soci......

蟠桃会会议平台
2018/04/24
0
0

没有更多内容

加载失败,请刷新页面

加载更多

在优麒麟中运行英雄联盟LOL

sudo apt install wine-stable sudo add-apt-repository ppa:lutris-team/lutris sudo apt install lutris 在lutris官网的game分类里找到英雄联盟这个游戏,然后进去那个页面, https://lutr......

gugudu
29分钟前
5
0
Mysql主从

一、mysql主从介绍 MySQL主从又叫做Replication、AB复制。简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的,MySQL主从基于binlog,主上须开启b...

wxy丶
33分钟前
6
0
商品SKU规格算法

思想 定义规格属性数据格式 定义生成SKU数据格式 完成点击多选框后生成的数据源 根据数据源生成SKU数据 根据生成的SKU数据做展示 代码示例 <!DOCTYPE html><html><head> <!-- 页面met...

chinahufei
41分钟前
1
0
面试点:Java 中 hashCode() 和 equals() 的关系

Java 中 hashCode() 和 equals() 的关系是面试中的常考点,如果没有深入思考过两者设计的初衷,这个问题将很难回答。除了应付面试,理解二者的关系更有助于我们写出高质量且准确的代码。 一....

爱码仕i
43分钟前
5
0
传智播客JNI第七讲 – JNI中的全局引用/局部引用/弱全局引用、缓存jfieldID和jmethodID的两种方式

讲解JNI中的全局引用/局部引用/弱全局引用、缓存jfieldID和jmethodID的两种方式,并编写两种缓存方式的示例代码。 1.从Java虚拟机创建的对象传到本地C/C++代码时会产生引用,根据Java的垃圾回...

shzwork
54分钟前
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部