JTScrollViewController 1.0.5

JTScrollViewController 1.0.5

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新版本2015年5月

Jonathan Vukovich Tribouharet维护。



  • Jonathan Tribouharet

JTScrollViewController 帮助您创建一个 UIViewController,它使用 UIScrollView 并占据所有可用空间,使用 Auto Layout 而不使用 nib 文件。它创建了为您的视图所需的所有约束。

安装

使用 CocoaPods,将此行添加到您的 Podfile 中。

pod 'JTScrollViewController', '~> 1.0'

用法

创建一个继承自 JTScrollViewController 的控制器。

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

@interface MyViewController : JTScrollViewController

@end

viewDidLoad 中创建您的视图,然后调用 configureConstraintsForSubviews 以创建所有约束。如果您不想 scrollView 在状态栏下方,可以调用 addVerticalSpacingForStatusBar

视图按添加到 contentView 的顺序显示。您需要通过设置它们框架的高度来设置每个视图的高度。您还可以通过设置它们框架的 y 属性来在每个视图之间添加间隔。

#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];
}

要求

  • iOS 7 或更高版本
  • 自动引用计数(ARC)

作者

许可证

JTScrollViewController 在 MIT 许可下发布。有关更多信息,请参阅 LICENSE 文件。