自定义PFLoginViewController的问题

时间:2015-08-22 17:23:15

标签: ios parse-platform pfloginviewcontroller

我已经将PFLoginViewController子类化,并且正在viewWillAppear进行我的UI自定义。这似乎适用于某些按钮和字段。

以下是应用首次加载时的登录屏幕:http://cl.ly/image/2J0v3K313W3A

以下自定义均已成立:

self.logInView?.logInButton?.setTitle("LOGIN", forState: UIControlState.Normal)
self.logInView?.logInButton?.titleLabel?.font = UIFont.openSansSemiBoldFontOfSize(18)
self.logInView?.signUpButton?.titleLabel?.font = UIFont.openSansSemiBoldFontOfSize(18)

我还有以下不需要的自定义:

self.logInView?.signUpButton?.setTitle("SIGN UP", forState: UIControlState.Normal)
self.logInView?.logInButton?.backgroundColor = UIColor(red: 136/255, green: 192/255, blue: 87/255, alpha: 1)
self.logInView!.signUpButton!.backgroundColor = UIColor(red: 136/255, green: 192/255, blue: 87/255, alpha: 1)

除了......如果我点按“注册”状态'底部的按钮,然后关闭注册视图控制器,当登录视图控制器重新出现时,“注册”'像应该的那样大写。但按钮背景没有改变。

http://cl.ly/image/0g0P1z0v1I1a

我无法理解为什么有些自定义工作有些不合适。代码全部在同一个地方。当视图出现时,setTitle如何为一个按钮而不是另一个按钮工作?

完全难倒。

**对于披露,我尝试在呈现登录控制器之前将所有自定义代码移动到。它没有区别。

1 个答案:

答案 0 :(得分:0)

背景颜色不是更新的原因是您已将它们作为整数传递。在整数的情况下,它们得到的结果将等于零。

self.logInView?.logInButton?.backgroundColor = UIColor(red: 136/255, green: 192/255, blue: 87/255, alpha: 1)
self.logInView!.signUpButton!.backgroundColor = UIColor(red: 136/255, green: 192/255, blue: 87/255, alpha: 1)

编译器将此代码读取为

self.logInView?.logInButton?.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
self.logInView!.signUpButton!.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)

要解决此问题,您需要将值作为双精度传递。 所以尝试运行代码

self.logInView?.logInButton?.backgroundColor = UIColor(red: 136.0/255.0, green: 192.0/255.0, blue: 87.0/255.0, alpha: 1.0)
self.logInView!.signUpButton!.backgroundColor = UIColor(red: 136.0/255.0, green: 192.0/255.0, blue: 87.0/255.0, alpha: 1.0)