JTScrollViewController 1.0.5

JTScrollViewController 1.0.5

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release May 2015

Maintained by Jonathan Vukovich Tribouharet.



  • By
  • Jonathan Tribouharet

JTScrollViewController help you to create pragmatically a UIViewController with a UIScrollView which take all the space available using Auto Layout without using a nib file. It creates all constraints required for your views.

Installation

With CocoaPods, add this line to your Podfile.

pod 'JTScrollViewController', '~> 1.0'

Usage

Create a controller which inherit from JTScrollViewController.

#import <UIKit/UIKit.h>
#import <JTScrollViewController.h>

@interface MyViewController : JTScrollViewController

@end

Create your views in the viewDidLoad and call configureConstraintsForSubviews for create all constraints. You can call addVerticalSpacingForStatusBar when you don't want the scrollView go under the status bar.

Each views are displayed in the orders they were added to contentView. You have to set the height of each views by setting the height of their frames. You can also add a space between each views by settings y property of their frames.

#import "MyViewController.h"

@implementation MyViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Add all your views to self.contentView
    // Do your stuff...
    {
        CGFloat spaceFromTop = 30.;
        UITextField *textField = [UITextField alloc] initWithFrame:CGRectMake(0, spaceFromTop, 0, 45)];
        [self.contentView addSubview:textField];
    }

    {
        UITextField *textField = [UITextField alloc] initWithFrame:CGRectMake(0, 5, 0, 45)];
        [self.contentView addSubview:textField];
    }

    {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 10, 0, 50)];
        [self.contentView addSubview:button];
    }

    // Add vertical space (22px) for the status bar
    // Use this when you don't have a navigation bar and you don't want the scroll go under the status bar
    [self addVerticalSpacingForStatusBar:YES];

    // Call configureConstraintsForSubviews for create all constraints
    [self configureConstraintsForSubviews];
}

Requirements

  • iOS 7 or higher
  • Automatic Reference Counting (ARC)

Author

License

JTScrollViewController is released under the MIT license. See the LICENSE file for more info.