0

解析を使用してアプリを構築していますが、ストーリーボードを使用して PFLoginViewController の外観とレイアウトを視覚的にカスタマイズできるかどうか疑問に思っていましたか? サブクラス化してコードを使用してカスタマイズできることはわかっていますが、可能であれば視覚的に行うことをお勧めします。

4

1 に答える 1

2

視覚的に行うことはできません。ただし、ストーリーボードに移動して次のようにすることで、独自のカスタム クラスを作成できます。

ナビゲーション コントローラーからのカスタム ログイン ビュー コントローラー

コードは、解析のために次のようになります。

import UIKit import Parse

class CustomLoginViewController: UIViewController {

@IBOutlet weak var usernameField: UITextField!
@IBOutlet weak var passwordField: UITextField!

var actInd : UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0,0, 150, 150)) as UIActivityIndicatorView

override func viewDidLoad() {
    super.viewDidLoad()

    self.actInd.center = self.view.center
    self.actInd.hidesWhenStopped = true
    self.actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
    view.addSubview(self.actInd)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

// MARK: Actions

@IBAction func loginAction(sender: AnyObject) {

    var username = self.usernameField.text
    var password = self.passwordField.text

    if (username.utf16Count < 4 || password.utf16Count < 5) {

        var alert = UIAlertView(title: "Invalid", message: "Username must be greater then 4 and Password must be greater then 5", delegate: self, cancelButtonTitle: "OK")
        alert.show()

    }else {

        self.actInd.startAnimating()

        PFUser.logInWithUsernameInBackground(username, password: password, block: { (user, error) -> Void in

            self.actInd.stopAnimating()

            if ((user) != nil) {

                var alert = UIAlertView(title: "Success", message: "Logged In", delegate: self, cancelButtonTitle: "OK")
                alert.show()

            }else {

                var alert = UIAlertView(title: "Error", message: "\(error)", delegate: self, cancelButtonTitle: "OK")
                alert.show()

            }

        })

    }

}

@IBAction func signUpAction(sender: AnyObject) {

    self.performSegueWithIdentifier("signUp", sender: self)

}

}

于 2016-01-11T03:26:14.833 に答える