我正在使用解析构建应用程序,我想知道是否可以自定义外观&使用故事板可视化布局PFLoginViewController?我知道可以使用代码对其进行子类化并使用代码进行自定义,但如果可能的话,我更愿意直观地进行操作?
答案 0 :(得分:2)
不可能在视觉上做到这一点。但是,您可以通过在故事板上创建自己的自定义类,并将其设置为:
对于解析,代码看起来像这样:
导入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)
}
}