2015-04-25 58 views
0

當我輸入下面的代碼,不被顯示在滾動視圖我添加文本框:的TextField不被添加到滾動型

.H

@interface FirstViewController : UIViewController <UIScrollViewDelegate> 
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView; 
@property (strong, nonatomic) UITextField *firstField; 
@property (strong, nonatomic) UITextField *secondField; 
@property (strong, nonatomic) UITextField *thirdField; 

.M(viewDidLoad中)

self.firstField.placeholder = @"First"; 
self.firstField.textAlignment = NSTextAlignmentCenter; 
self.firstField.font = [UIFont fontWithName:@"Helvetica Neue Light" size:50.0]; 

self.secondField.placeholder = @"Second"; 
self.secondField.textAlignment = NSTextAlignmentCenter; 
self.secondField.font = [UIFont fontWithName:@"Helvetica Neue Light" size:50.0]; 

self.thirdField.placeholder = @"Third"; 
self.thirdField.textAlignment = NSTextAlignmentCenter; 
self.thirdField.font = [UIFont fontWithName:@"Helvetica Neue Light" size:50.0]; 

[self.scrollView addSubview:self.firstField]; 
[self.firstField autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeRight]; 
[self.firstField autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.scrollView]; 
[self.firstField autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.scrollView]; 

[self.scrollView addSubview:self.secondField]; 
[self.secondField autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.firstField]; 
[self.secondField autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.scrollView]; 
[self.secondField autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.scrollView]; 

[self.scrollView addSubview:self.thirdField]; 
[self.thirdField autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.secondField]; 
[self.thirdField autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeLeft]; 
[self.thirdField autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.scrollView]; 
[self.thirdField autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.scrollView]; 

self.automaticallyAdjustsScrollViewInsets = NO; 

我有self.scrollView是在一個scrollView的方式(在pageviewcontroller)。我使用PureLayout來定位文本字段,並且我非常確定我做的方式是正確的。有什麼我失蹤?

回答

1

是你缺少一些代碼,如果你wan't添加的UITextField程序,您必須設置大小和位置你認爲,這樣的事情:

self.firstField.frame = CGRectMake(10, 200, 300, 40); 

我希望這會幫助你。

+0

我把這段代碼放在'[self.scrollView addSubview:self.firstField]'後面,它仍然不顯示。 – smecperson

0

AutoLayout與UIScrollView的工作方式稍有不同:它與其contentView而不是其框架相關。 This is explained here

默認情況下,您需要設置您的UIScrollView的contentView屬性,因爲它的CGSizeZero屬性。然後,如果你希望你的3個UITextfields並排出現,你將不得不改變它們的寬度約束,否則它們將填充整個contentSize。