I am creating some 6 to 10 textfields dynamically and also some labels dynamically.I want to implement scroll view for this.how to do it?i have dragged a scroll view and implemented below code in the ViewDidLoad method.Even i connected IBOutlet for scrollview.But nothing is working.
Can anyone tel me with sample where i can add all this textfields into a scrollview and when it exceeds scroll view limit it should be scrolled down to see the textfields.
- (void)viewDidLoad
{
[self textField1];
[self textField2];
[super viewDidLoad];
scrollView.frame = CGRectMake(0, 0, 600, 800);
[scrollView setContentSize:CGSizeMake(500, 800)];
}
// code for creating textfield dynamically using -(void)textfield function
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 250, 200, 35)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 300, 200, 35)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 350, 200, 35)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 400, 200, 35)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 450, 200, 35)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 500, 200, 35)];
In your Main View, add one Scroll View. After that inside the Scroll View add UIView as Subview.
Like This: MainView –>
ScrollView —>
SubView
Then in ViewDidLoad:
After that add TextFields Dynamically inside the SubView, not in MainView.