내 앱의 간단한 가입 화면을 만들고 있습니다. 나는 Storyboards
을 사용하지 않고 코드로 모든 것을하고있다. 그래서, 키보드를위한 공간을 허용하기 위해 내 화면의 동적 스크롤을 용이하게하기 위해 UITextFields
을 UIScrollView
안에 삽입하는 표준 Apple 관행을 사용하고 있지만, 전혀 보이지 않습니다!UIViewController에 UIScrollView가 표시되지 않습니다.
코드 :
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self registerForKeyboardNotifications];
self.title = NSLocalizedString(@"Register", nil);
[self.navigationController setNavigationBarHidden:NO];
// Because Rendering Bug in iOS 7
self.view.backgroundColor = [UIColor whiteColor];
UIScrollView *scrollView = [[UIScrollView alloc] init];
_scrollView.frame = self.view.frame;
_scrollView.scrollEnabled = YES;
_scrollView.showsVerticalScrollIndicator = YES;
_scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2);
[self.view addSubview:scrollView];
// Personal Image View
UIButton *profileImageButton = [UIButton buttonWithType:UIButtonTypeSystem];
profileImageButton.frame = CGRectMake(0, 0, 80, 80);
profileImageButton.center = CGPointMake(self.view.center.x, 80);
[profileImageButton setBackgroundImage:[UIImage imageNamed:@"DefaultAvatar"] forState:UIControlStateNormal];
[profileImageButton addTarget:self action:@selector(uploadImage) forControlEvents:UIControlEventTouchUpInside];
[_scrollView addSubview:profileImageButton];
// Username Text Field
_usernameTextField = [[UITextField alloc] init];
_usernameTextField.frame = CGRectMake(0, 0, self.view.frame.size.width, 64);
_usernameTextField.center = CGPointMake(self.view.center.x, 225);
_usernameTextField.placeholder = @"\tUsername";
_usernameTextField.layer.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0].CGColor;
_usernameTextField.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:20.0];
_usernameTextField.autocorrectionType = UITextAutocorrectionTypeNo;
[_scrollView addSubview:_usernameTextField];
// Password Text Field
_passwordTextField = [[UITextField alloc] init];
_passwordTextField.frame = CGRectMake(0, 0, self.view.frame.size.width, 64);
_passwordTextField.center = CGPointMake(self.view.center.x, 320);
_passwordTextField.placeholder = @"\tPassword";
_passwordTextField.layer.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0].CGColor;
_passwordTextField.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:20.0];
_passwordTextField.autocorrectionType = UITextAutocorrectionTypeNo;
[_scrollView addSubview:_passwordTextField];
}