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.
With CocoaPods, add this line to your Podfile.
pod 'JTScrollViewController', '~> 1.0'
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];
}
JTScrollViewController is released under the MIT license. See the LICENSE file for more info.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。