0

I've subclassed PFLoginViewController and am doing my UI customizations in viewWillAppear. This seems to work fine for some buttons and fields.

Here is my login screen when the app first loads: http://cl.ly/image/2J0v3K313W3A

The following customizations all take hold:

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

I also have the following customizations that don't take:

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)

Except...If I tap the 'Sign Up' button at the bottom, then dismiss the sign up view controller, when the login view controller re-appears, the 'sign up' is capitalized like it should be. But the button background hasn't changed.

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

I just can't wrap my head around why some of the customizations work and some don't. The code is all in the same place. How can setTitle work for one button but not the other when the view fist appears?

Totally stumped.

** For disclosure, I have tried moving all my customization code to before presenting the login controller. It made zero difference.

4

1 回答 1

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)
于 2015-08-22T18:23:57.657 回答