• Stars
    star
    423
  • Rank 101,882 (Top 3 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 5 years ago

Reviews

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

Repository Details

Vertically stack views using Auto Layout, with an order specific subclass that uses view tags for ordering.

ORStackView

Build Status Coverage Status Version Platform

Makes setting up a collection of stacked views simple. Uses FLKAutoLayout to simplify the API, you should probably be using it anyway. Depending on demand this can be switched out. If you're interested in more information you can read ORStackView.h

Recommendation

It's probably not the best idea to use ORStackView in a new project, given that UIStackView exists, and there are a lot of pods that aim to have a compatible API with that. Some things that ORStackView does better: View Controllers, and internal margins for individual items. However, you'd probably find yourself fighting the grain in the future.

ORStackView

You can create an ORStackView and simply add subviews to it in the order in which you'd like them to appear. New subviews are added to the bottom of the ORStackView. In the this example, tapping the first subview will add a new subview to the bottom of the stack.

- (void)loadView
{
    self.view = [[ORStackView alloc] init];
}

- (void)viewDidLoad
{
  ORColourView *view1 = [[ORColourView alloc] init];
  view1.text = @"ORStackView - Tap Me";
  view1.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 40};

  UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
    initWithTarget:self action:@selector(addView)];
  [view1 addGestureRecognizer:tapGesture];

  ORColourView *view2 = [[ORColourView alloc] init];
  view2.text = @"Subtitle";
  view2.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 20 };

  ORColourView *view3 = [[ORColourView alloc] init];
  view3.text = @"By default, new subviews are added to the bottom of ORStackView.";
  view3.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 100 };

  [self.view addSubview:view1 withPrecedingMargin:20 sideMargin:30];
  [self.view addSubview:view2 withPrecedingMargin:40 sideMargin:70];
  [self.view addSubview:view3 withPrecedingMargin:30 sideMargin:20];
}

- (void)addView
{
  ORColourView *view = [[ORColourView alloc] init];
  view.text = @"Tap to remove";
  view.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 24 };
  [self.view addSubview:view withPrecedingMargin:5 sideMargin:40];
}

ORStackView with ordering

If you have views which should only appear once you've got confirmation from an external source, you can add your subviews using insertSubview:atIndex:withPrecedingMargin:, insertSubview:atIndex:withPrecedingMargin:sideMargin:, insertSubview:belowSubview:withPrecedingMargin: or insertSubview:aboveSubview:withPrecedingMargin:

In this example, subviews appear in a different order than they are added chronologically. Tapping the first subview adds a new subview to the middle of the stack.

- (void)loadView
{
    self.view = [[ORStackView alloc] init];
}

- (void)viewDidLoad
{
  ORColourView *view1 = [[ORColourView alloc] init];
  view1.text = @"1 - ORStackView - Tap Me";
  view1.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 40};
  UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
    initWithTarget:self action:@selector(addView)];
  [view1 addGestureRecognizer:tapGesture];

  ORColourView *view2 = [[ORColourView alloc] init];
  view2.text = @"2 - You can control the order your ORStackView's subviews";
  view2.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 50 };

  ORColourView *view3 = [[ORColourView alloc] init];
  view3.text = @"3 - Lorem ipsum, etc. etc.";
  view3.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 20 };

  ORColourView *view4 = [[ORColourView alloc] init];
  view4.text = @"4 - Lorem ipsum, etc. etc.";
  view4.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 20 };

  [self.view insertSubview:view2 atIndex:0 withPrecedingMargin:20 sideMargin:20];
  [self.view insertSubview:view4 atIndex:1 withPrecedingMargin:15 sideMargin:20];
  [self.view insertSubview:view1 atIndex:0 withPrecedingMargin:10 sideMargin:20];
  [self.view insertSubview:view3 atIndex:2 withPrecedingMargin:10 sideMargin:20];
}

- (void)addView
{
  ORColourView *view = [[ORColourView alloc] init];
  view.text = @"Tap to remove";
  view.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 24 };
  [self.view addSubview:view withPrecedingMargin:5 sideMargin:40];
}

ORTagBasedAutoStackView

Another option is to use ORTagBasedAutoStackView to order your subviews visually in a different order than you will be adding them chronologically. ORTagBasedAutoStackView uses view tags to specify the order in which views will appear from top to bottom. For example these views will be ordered correctly regardless of the insertion order chronologically. Tapping the first view adds a new view with a tag of 3 to the middle of the stack.

- (void)loadView
{
    self.view = [[ORTagBasedAutoStackView alloc] init];
}

- (void)viewDidLoad
{
  ORColourView *view1 = [[ORColourView alloc] init];
  view1.text = @"Tap Me\ntag = 1";
  view1.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 70};
  view1.tag = 1;

  UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
    initWithTarget:self action:@selector(addView)];
  [view1 addGestureRecognizer:tapGesture];

  ORColourView *view2 = [[ORColourView alloc] init];
  view2.text = @"ORTagBasedAutoStackView uses view tags to order your subviews\ntag = 2";
  view2.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 70 };
  view2.tag = 2;

  ORColourView *view4 = [[ORColourView alloc] init];
  view4.text = @"tag = 4";
  view4.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 50 };
  view4.tag = 4;

  ORColourView *view5 = [[ORColourView alloc] init];
  view5.text = @"tag = 5";
  view5.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 60 };
  view5.tag = 5;

  [self.view addSubview:view2 withPrecedingMargin:10 sideMargin:40];
  [self.view addSubview:view5 withPrecedingMargin:20 sideMargin:20];
  [self.view addSubview:view4 withPrecedingMargin:10 sideMargin:20];
  [self.view addSubview:view1 withPrecedingMargin:20 sideMargin:30];
}

- (void)addView
{
  if ([[self.view.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"tag = 3"]] count] > 0) return;

  ORColourView *view3 = [[ORColourView alloc] init];
  view3.text = @"tap to remove me\ntag = 3";
  view3.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 50 };
  view3.tag = 3;

  [self.view addSubview:view3 withPrecedingMargin:20 sideMargin:70];
}

ORSplitStackView

ORSplitStackView is a view containing two ORStackView columns. Add subviews to the leftStack and rightStack views. ORSplitStackView adjusts its height to fit the taller of the two stack views.

- (void)loadView
{
  self.view = [[UIView alloc] init];
}

- (void)viewDidLoad
{
  ORSplitStackView *splitView = [[ORSplitStackView alloc] initWithLeftPredicate:@"155" rightPredicate:@"130"];
  [self.view addSubview:splitView];
  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:splitView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
  if ([self respondsToSelector:@selector(topLayoutGuide)]) {
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:splitView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]];
  }

  splitView.backgroundColor = [UIColor purpleColor];
  ORColourView *left1 = [[ORColourView alloc] init];
  left1.text = @"Tap Me";
  left1.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 50};

  ORColourView *right1 = [[ORColourView alloc] init];
  right1.text = @"Tap Me";
  right1.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 60};

  UITapGestureRecognizer *leftGesture = [[UITapGestureRecognizer alloc]
    initWithTarget:self action:@selector(addView:)];
  [left1 addGestureRecognizer:leftGesture];
  UITapGestureRecognizer *rightGesture = [[UITapGestureRecognizer alloc]
    initWithTarget:self action:@selector(addView:)];
  [right1 addGestureRecognizer:rightGesture];

  ORColourView *left2 = [[ORColourView alloc] init];
  left2.text = @"ORSplitStackView is a view containing two stack views.";
  left2.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 90};

  ORColourView *left3 = [[ORColourView alloc] init];
  left3.text = @"ORSplitStackView adjusts its height to fit its content";
  left3.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 75};

  ORColourView *right2 = [[ORColourView alloc] init];
  right2.text = @"a view";
  right2.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 45};

  ORColourView *right3 = [[ORColourView alloc] init];
  right3.text = @"a view";
  right3.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 40};

  [splitView.leftStack addSubview:left1 withPrecedingMargin:0 sideMargin:10];
  [splitView.leftStack addSubview:left2 withPrecedingMargin:10 sideMargin:5];
  [splitView.leftStack addSubview:left3 withPrecedingMargin:10 sideMargin:15];
  [splitView.rightStack addSubview:right1 withPrecedingMargin:0 sideMargin:15];
  [splitView.rightStack addSubview:right2 withPrecedingMargin:10 sideMargin:10];
  [splitView.rightStack addSubview:right3 withPrecedingMargin:10 sideMargin:5];
}

- (void)addView:(UITapGestureRecognizer *)gesture
{
  ORColourView *view = [[ORColourView alloc] init];
  view.text = @"Tap to remove";
  view.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 24 };
  [(ORStackView *)gesture.view.superview addSubview:view withPrecedingMargin:5 sideMargin:10];
}

Example Usage

pod try ORStackView or to run the example project; clone the repo, and run pod install from the Project directory.

Installation

ORStackView is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "ORStackView"

Author

Orta Therox, [email protected]

License

ORStackView is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

ARAnalytics

Simplify your iOS/Mac analytics
Objective-C
1,836
star
2

cocoapods-keys

A key value store for storing per-developer environment and application keys
Ruby
1,551
star
3

GIFs

A Mac App for finding GIFs
Objective-C
602
star
4

pragmatic-testing

Pragmatic testing ebook
Ruby
542
star
5

vscode-twoslash-queries

VS Code extension which adds support for twoslash queries into typescript projects
TypeScript
403
star
6

Snapshots

An Xcode Plugin to show the state of FBSnapshot Tests.
Objective-C
363
star
7

typescript-notes

High-level notes about TypeScript
319
star
8

cocoapods-fix-react-native

A CocoaPods plugin for hot-patching React Native per-version
Ruby
243
star
9

You-Can-Do-It

Is learning a new language getting you down? Worry not, this Xcode plugin will keep you motivated.
Objective-C
240
star
10

chairs

Swap around your iOS Simulator Documents
Ruby
227
star
11

vscode-react-native-storybooks

Inline your Storybooks server in VS Code
TypeScript
164
star
12

SpeedS-ver

A Mac OS X Screensaver - Shows people doing speedruns as your screensaver.
Objective-C
146
star
13

iMessage-Style-Receding-Keyboard

A demo application for showing how to drag the keyboard down with your finger.
Objective-C
137
star
14

wwdc_parties_2014

What is happening in WWDC 2014
109
star
15

Wallpapers

A Mac App for Downloading Wallpapers.
Objective-C
92
star
16

RedXcode

When Xcode is being ran in a debugger, make it obvious that it's in dev mode by turning it red and adding a cool banner.
Objective-C
91
star
17

twitter-urls-to-clients

Safari / Chrome extension to convert all Twitter.com urls to mac twitter app specific URLs
JavaScript
87
star
18

Puttio

A Universal iOS App for Put.IO
Objective-C
87
star
19

recommendations

A source-format agnostic way of providing recommendations
Ruby
82
star
20

awesome-typescript-derived-languages

Projects which have taken "TypeScript" and made it more than just 'JS with Types'
82
star
21

dna

my dna in raw text
79
star
22

Essence

A VSCode UI.
CSS
77
star
23

ORSimulatorKeyboardAccessor

Use your keyboard in the iOS simulator with a blocks based API
Objective-C
73
star
24

AppCode

Custom Setup for App Code
66
star
25

Heuristics-for-vendoring-MIT-code

A quick readme covering the cases where you would import code
59
star
26

danger-junit

Lets you report your test suite problems back to the PR elegantly
Ruby
57
star
27

keyboard_shortcuts

Notes on Keyboard Shortcuts for the Mac. Oriented towards technical but not programmers.
53
star
28

Snapshots-Peek

Show-off your Snapshots in Xcode
Objective-C
52
star
29

vscode-playdate

TypeScript
51
star
30

TypeScript-TSServer-Plugin-Template

TypeScript
51
star
31

gh_inspector

A gem that makes it easy to find existing issues for exceptions via GitHub issues
Ruby
49
star
32

WibbleQuest

A Text Adventure Game framework for iOS
Objective-C
46
star
33

OROpenSubtitleDownloader

An Obj-C API for Searching and Downloading Subtitles from OpenSubtitles.
Objective-C
45
star
34

Mixtapes

an iPad app for making mixtapes using Spotify
Objective-C
44
star
35

react-storybooks-relay-container

Storybook template for Relay containers
JavaScript
39
star
36

typescript-stickers

Stickers for TypeScript
39
star
37

youtube

Scripts for videos and talks
39
star
38

GIFKit

A source for GIFs
Objective-C
37
star
39

OROpenInAppCode

Opens the current xcworkspace / xcproject in AppCode.
Objective-C
37
star
40

vscode-ios-common-files

This Extension adds Ruby syntax highlighting for CocoaPods and Fastlane stuff
JavaScript
35
star
41

playground-slides

Make presentations in the TypeScript playground
CSS
35
star
42

travish

Badly emulates the Travis workflow from a .travis.yml
Ruby
34
star
43

danger-plugin-yarn

Provides dependency information on dependency changes in a PR *
TypeScript
30
star
44

Snapshots-app

A Mac App for viewing view-based Snapshot tests
Objective-C
30
star
45

Preferences

Add preferences support for your Xcode plugins.
Objective-C
29
star
46

cocoapods-no-dev-schemes

Removes all the CocoaPods Shared Schemes from Developer Pods
Ruby
27
star
47

relay-redwood-app-example

An example of using Relay in Redwood
TypeScript
27
star
48

OctoDog

A Swift PM module for accessing the GitHub API
Swift
27
star
49

orta

Profile bio
JavaScript
26
star
50

github-webhook-event-types

TypeScript type definitions for GitHub's events
TypeScript
26
star
51

cocoapods-xcautotest

Automatically inject new test classes into your iOS simulator without restarts.
C
26
star
52

danger-plugin-spellcheck

Spell checks any created or modified code or markdown files in a GitHub PR
TypeScript
26
star
53

GotTheRoutesLikeSwagger

Ruby app to take a Swagger API and generate NSURLRequests.
Ruby
25
star
54

cocoapods-always-be-bundleing

A CocoaPods Plugin that stops
Ruby
25
star
55

nightly-profile-updater

HTML
25
star
56

ar_dispatch

Dispatch functions run async code synchronous in tests
Objective-C
25
star
57

cocoapods-expert-difficulty

Make your CocoaPods experience even harder, by ignoring platforms from lib authors
Ruby
24
star
58

PonyDebuggerApp

A host app for Pony Debugger
Objective-C
24
star
59

danger-plugin-lighthouse

Print your Lighthouse reports to your PR
HTML
22
star
60

typescript-web-extension

A cross-browser extension for working with TypeScript code
JavaScript
22
star
61

github-clippers

Automate away the annoying requests for you to close your branches after PR merges in Safari
JavaScript
22
star
62

Relay-Artist-Example

An example React Native app using Relay to access the Artsy GraphQL API
Objective-C
22
star
63

FUSEHub

A MacFUSE filesystem for browsing a github repository
Objective-C
21
star
64

playground-collaborate

Collaborate in the TypeScript Playground
TypeScript
21
star
65

ImageCachingExamples

A complete example of using SDWebImage to do synchronous image loading for FBSnapshots
Swift
18
star
66

github-activity-writer

TypeScript
18
star
67

GitDawg

React Native Components for GitHawk
Ruby
17
star
68

Tinker

A Text Adventure Game Framework for Swift
Swift
17
star
69

pull-lock

Run commands based on changes during a git pull
TypeScript
17
star
70

playground-transformer-timeline

Lets you see each stage of the transform process for a TypeScript JS + DTS emit as a timeline.
TypeScript
16
star
71

FastImageCacheExample

The simplest possible use of FastImageCache
Objective-C
16
star
72

gh-commentify

A repo you can use to work-around GH issue comment request limits
TypeScript
15
star
73

vscode-themes

vscode-themes
JavaScript
15
star
74

playground-clippy

JavaScript
15
star
75

vigilant

Glues Quick & Nimble together. Makes sure you run an expectation on every test.
Objective-C
15
star
76

redwood-object-identification

TypeScript
14
star
77

md-type-tables

JavaScript
14
star
78

mogenerator-template

A mogenerator template that generates more human-readable _Class files
14
star
79

react-native-45-typescript-example

An example of taking react-native's default template and making it work with typescript
JavaScript
14
star
80

notes

An exploration on keeping public notes
CSS
13
star
81

systems-theory

React Native in TypeScript that feels good
JavaScript
13
star
82

nakama-typescript-example

An example of a nakama server using 2022's bleeding edge TypeScript tooling
JavaScript
13
star
83

Arena-for-Safari

Adds an are.na button to Safari
JavaScript
13
star
84

playground-typescript-json-schema

TypeScript
12
star
85

video-notes

notes for video editing
12
star
86

snazzy

A Snazzy README generator for your public API built on SourceKitten
Ruby
12
star
87

playground-plugin-tsquery

Run TSQuery in the TypeScript Playground
TypeScript
12
star
88

orta.github.com

orta blog
JavaScript
12
star
89

markdown-magic-inline-types

Inline TypeScript types into markdown files
JavaScript
12
star
90

snake-in-typescript

Lua
11
star
91

redwood-codegen-api-types

Replacement types generator for your Redwood API
TypeScript
11
star
92

omakase-create-react-app-example

Using CRA 2.1 to re-create a chunk the the omakase stack
JavaScript
11
star
93

windows-notes

Things to think about in switching from macOS to Windows
11
star
94

snowpack-plugin-hmr-phaser

JavaScript
11
star
95

cocoapods_generate_unit_tests

An experiment in scripting an entirely runnable xcodeproject + tests in ruby
Ruby
10
star
96

life

General issue tracker for things that I should get around to doing
10
star
97

playground-ts-scanner

TypeScript
10
star
98

vscode-typescript-playground-links

An extension which improves working with the TypeScript playground
TypeScript
10
star
99

ts-playgrounds-github

Quickly go from a TS code sample to the TypeScript playground
Objective-C
10
star
100

Steps

A iPhone 5S -> Fitbit app
Objective-C
10
star