• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parus is simple chain style auto-layout helper for objective-c.

Language Version Licence Platform

Parus

Parus is a small objective-c DSL for AutoLayout in code.

Features

  • It is easy to create constraints - just like writing a sentence;
  • More compact and semantical than usual NSAutoLayout;
  • Flexibility in creating constraints - you specify only parameters that you need;
  • Autocomplete rocks!

Usage

Single constraint

NSLayoutConstraint:

[NSLayoutConstraint constraintWithItem:view
                             attribute:NSLayoutAttributeLeft
                             relatedBy:NSLayoutRelationEqual
                                toItem:superview
                             attribute:NSLayoutAttributeLeft
                            multiplier:2.0
                              constant:10];

Using Parus:

PVLeftOf(view).equalTo.leftOf(superview).multipliedTo(2).plus(10).asConstraint;

Using default values make it even shorter:

[NSLayoutConstraint constraintWithItem:view
                             attribute:NSLayoutAttributeLeft
                             relatedBy:NSLayoutRelationEqual
                                toItem:nil
                             attribute:NSLayoutAttributeNotAnAttribute
                            multiplier:1.0
                              constant:10];
PVLeftOf(view).equalTo.constant(10).asConstraint;

Visual Formatting Language (VFL)

Simple VFL constraints:

[NSLayoutConstraint constraintsWithVisualFormat:@"|-padding-[view]-padding-|"
                                        options:(NSLayoutFormatAlignAllTop | 
                                                 NSLayoutFormatDirectionLeadingToTrailing)
                                        metrics:@{@"padding" : @20}
                                          views:NSDictionaryOfVariableBindings(view)];
PVVFL(@"|-padding-[view]-padding-|").alignAllTop.fromLeadingToTrailing.withViews(NSDictionaryOfVariableBindings(view)).metrics(@{@"padding": @20}).asArray;

With special masks and defaults:

[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view1][view2][view3]|"
                                        options:(NSLayoutFormatAlignAllLeft | 
                                                 NSLayoutFormatAlignAllRight)
                                        metrics:nil
                                          views:NSDictionaryOfVariableBindings(view1, view2, view3)];
PVVFL(@"V:|[view1][view2][view3]|").alignAllLeftAndRight.withViews(NSDictionaryOfVariableBindings(view1, view2, view3)).asArray;

Groups

There is available feature that helps you group constraints and produce even less code. Enjoy!

[someView addConstraint:[NSLayoutConstraint constraintWithItem:view
                           						     attribute:NSLayoutAttributeLeft
                             						 relatedBy:NSLayoutRelationEqual
                                						toItem:nil
                             						 attribute:NSLayoutAttributeNotAnAttribute
                            						multiplier:1.0
                              						  constant:10]];
[someView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view1][view2][view3]|"
                                        						 options:(NSLayoutFormatAlignAllLeft | 
                                                 						  NSLayoutFormatAlignAllRight)
                                        						 metrics:nil
                                          						   views:NSDictionaryOfVariableBindings(view1, view2, view3)]];
[someView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view1]|"
                                        						 options:NSLayoutFormatDirectionLeadingToTrailing
                                        						 metrics:nil
                                          						   views:NSDictionaryOfVariableBindings(view1)]];
[someView addConstraints:PVGroup(@[PVLeftOf(view).equalTo.constant(10),
								   PVVFL(@"V:|[view1][view2][view3]|").alignAllLeftAndRight,
								   PVVFL(@"H:|[view1]|")
								   ]).withViews(NSDictionaryOfVariableBindings(view1, view2, view3)).asArray];

You can also use usual NSLayoutConstraint or NSArray of NSLayoutConstraint as an item for PVGroup(). Following code is totally acceptable:

NSLayoutConstraint* usualConstraint = [NSLayoutConstraint constraintWithItem:... blablabla very long constraint definition ...];
NSArray* usualConstraints = [NSLayoutConstraint constraintsWithVisualFormat:... blabla ...];

[someView addConstraints:PVGroup(@[usualConstraint, usualConstraints]).asArray];

Alternatives

Installation

Use cocoapods!

pod 'Parus'
#import <Parus/Parus.h>

TODO

  • Mac OS X support;
  • Extend debug description;
  • Category for NSString as a start point for creating VFL.

More information

Visit our wiki

Bitdeli Badge

More Repositories

1

SwiftUI-UDF-Demo

This project is a demonstration of Unidirectional data flow techniques is conjunction with SwiftUI
Swift
53
star
2

HandlingUserInput

This is my rework of Apple example how to handle user input in SwiftUI apps
Swift
41
star
3

GwentBrowser

Simple browser of Gwent cards created as demonstration of Redux approach for simple API interaction
Swift
35
star
4

SwiftRecoil

SwiftUI adaptation of Recoil.JS library. Just demo, not ready for production.
Swift
18
star
5

ReduxStore

This is a Swift implementation of Store component from Redux approach
Swift
14
star
6

recoil

Swift
9
star
7

swift-elm-counter

Demo application for simple counter.
Swift
7
star
8

CardBrowser2.0

Another demo of redux card browsing
Swift
7
star
9

ReduxNotes

Demo repo for oversimplified note app using redux and swift
Swift
6
star
10

Todo-MVVM

Simple example of iOS Application using RAC and MVVM
Objective-C
6
star
11

FMVPDemo

Demo project from mobiconf 2016
Swift
5
star
12

arrow

Domain specific language for expressing unidirectional state transformation.
Swift
5
star
13

Sensus

Sensus is small objective-c DSL for extracting strongly typed data from NSDictionary.
Objective-C
5
star
14

FRPDemo

Demonstration of FRP
Objective-C
3
star
15

JustFuture

Simple future for Swift
Swift
3
star
16

Morpheus

Objective-C lib for UIView CSS like styling
Objective-C
2
star
17

BillScaner

Swift
2
star
18

mywarmind.net

https://mywarmind.net
HTML
2
star
19

ReduxWorkshop

Swift
2
star
20

VersionedCodable

Small package for providing versioning to codable structures
Swift
2
star
21

LiveNode

Experimental internal chat on nodeJS
JavaScript
1
star
22

scryfall-swiftui

SwiftUI Client for Scryfall.com
Swift
1
star
23

ViewTester

App structure and example that allow test different parts of iOS app independently
1
star
24

TCG

World of Warcraft TCG Modelling.
1
star
25

DlGStateMachine

block oriented FSM for objective c
1
star
26

PathfinderKit

Implementation of Pathfinder board card game rule set in Swift
Swift
1
star
27

WoW-TCG

Game wrapper for World of Warcraft Trading Card Game
C#
1
star
28

Auto-localization

1
star