Skip to content

Update code snippets for sign up & log in view controller #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 33 additions & 37 deletions _includes/ios/user-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ logInController.delegate = self;
```swift
var logInController = PFLogInViewController()
logInController.delegate = self
self.presentViewController(logInController, animated:true, completion: nil)
self.present(logInController, animated:true, completion: nil)
```
</div>

Expand All @@ -48,11 +48,11 @@ Any of the above features can be turned on or off. The options can be set using
| PFLogInFieldsDismissButton);
```
```swift
logInController.fields = [PFLogInFields.UsernameAndPassword,
PFLogInFields.LogInButton,
PFLogInFields.SignUpButton,
PFLogInFields.PasswordForgotten,
PFLogInFields.DismissButton]
logInController.fields = [PFLogInFields.usernameAndPassword,
PFLogInFields.logInButton,
PFLogInFields.signUpButton,
PFLogInFields.passwordForgotten,
PFLogInFields.dismissButton]
```
</div>

Expand All @@ -72,9 +72,9 @@ logInController.fields = (PFLogInFieldsUsernameAndPassword
| PFLogInFieldsTwitter);
```
```swift
logInController.fields = [PFLogInFields.UsernameAndPassword,
PFLogInFields.Facebook,
PFLogInFields.Twitter]
logInController.fields = [PFLogInFields.usernameAndPassword,
PFLogInFields.facebook,
PFLogInFields.twitter]
```
</div>

Expand All @@ -91,7 +91,7 @@ logInController.facebookPermissions = @[ @"friends_about_me" ];
var logInController = PFLogInViewController()
logInController.delegate = self
logInController.facebookPermissions = [ "friends_about_me" ]
self.presentViewController(logInController, animated:true, completion:nil)
self.present(logInController, animated:true, completion:nil)
```
</div>

Expand All @@ -112,11 +112,11 @@ When the user signs in or cancels, the `PFLogInViewController` notifies the dele
```
```swift
func logInViewController(controller: PFLogInViewController, didLogInUser user: PFUser!) -> Void {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismiss(animated: true, completion: nil)
}

func logInViewControllerDidCancelLogIn(controller: PFLogInViewController) -> Void {
self.dismissViewControllerAnimated(true, completion: nil)
func logInViewControllerDidCancelLog(in controller: PFLogInViewController) -> Void {
self.dismiss(animated: true, completion: nil)
}
```
</div>
Expand Down Expand Up @@ -146,15 +146,15 @@ You might want to use your own logo or background image. You can achieve this by
@end
```
```swift
class MyLogInViewController : PFLogInViewController {
class MyLogInViewController: PFLogInViewController {

override func viewDidLoad() {
super.viewDidLoad()

self.view.backgroundColor = UIColor.darkGrayColor()
self.view.backgroundColor = .darkGray

let logoView = UIImageView(image: UIImage(named:"logo.png"))
self.logInView.logo = logoView
let logoView = UIImageView(image: UIImage(named:"logo.png"))
self.logInView?.logo = logoView
}

}
Expand All @@ -172,7 +172,7 @@ logInController.signUpController = [[MySignUpViewController alloc] init];
```swift
let logInController = MyLogInViewController()
logInController.signUpController = MySignUpViewController()
self.presentViewController(logInController, animated: true, completion: nil)
self.present(logInController, animated: true, completion: nil)
```
</div>

Expand Down Expand Up @@ -272,11 +272,7 @@ signUpController.fields = (PFSignUpFieldsUsernameAndPassword
| PFSignUpFieldsDismissButton);
```
```swift
signUpController.fields = [PFSignUpFields.usernameAndPassword,
PFSignUpFields.signUpButton,
PFSignUpFields.email,
PFSignUpFields.additional,
PFSignUpFields.dismissButton]
signUpController.fields = [.usernameAndPassword, .signUpButton, .email, .additional, .dismissButton]
```
</div>

Expand All @@ -298,11 +294,11 @@ When the user signs up or cancels, the `PFSignUpViewController` notifies the del
```
```swift
func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) -> Void {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismiss(animated: true, completion: nil)
}

func signUpViewControllerDidCancelSignUp(signUpController: PFSignUpViewController) -> Void {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismiss(animated: true, completion: nil)
}
```
</div>
Expand Down Expand Up @@ -338,10 +334,10 @@ class MySignUpViewController : PFSignUpViewController {
override func viewDidLoad() {
super.viewDidLoad()

self.view.backgroundColor = UIColor.darkGrayColor()
self.view.backgroundColor = .darkGray

let logoView = UIImageView(image: UIImage(named: "logo.png"))
self.signUpView.logo = logoView // 'logo' can be any UIView
let logoView = UIImageView(image: UIImage(named: "logo.png"))
self.signUpView?.logo = logoView // 'logo' can be any UIView
}
}
```
Expand All @@ -360,12 +356,12 @@ Often you will want to run some client-side validation on the sign up informatio
}
```
```swift
func signUpViewController(signUpController: PFSignUpViewController!,
shouldBeginSignUp info: [NSObject : AnyObject]!) -> Bool {
if let password = info?["password"] as? String {
return password.utf16Count >= 8
}
return false
func signUpViewController(_ signUpController: PFSignUpViewController,
shouldBeginSignUp info: [String : String]) -> Bool {
if let password = info["password"] {
return password.utf16.count >= 8
}
return false
}
```
`info` is a dictionary that contains all sign up fields, such as username, password, email, and additional.
Expand Down Expand Up @@ -400,20 +396,20 @@ class MySignUpViewController : PFSignUpViewController {
override func viewDidLoad() {
super.viewDidLoad()

self.signUpView.usernameField.placeholder = "phone"
self.signUpView?.usernameField?.placeholder = "phone"
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

self.signUpView.signUpButton.frame = CGRectMake(...) // Set a different frame.
self.signUpView?.signUpButton?.frame = CGRectMake(...) // Set a different frame.
}

}
```
</div>

Developer interested in this kind of customization should take a look at the interface of [`PFSignUpView`](http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFSignUpView.html), where all customizable properties are documented.
Developers interested in this kind of customization should take a look at the interface of [`PFSignUpView`](http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFSignUpView.html), where all customizable properties are documented.

### Portrait and Landscape

Expand Down