Ios 如何更改UIButton的颜色:Parse的PFLoginViewController中的注册按钮
如何更改ParseIos 如何更改UIButton的颜色:Parse的PFLoginViewController中的注册按钮,ios,objective-c,uiview,uibutton,parse-platform,Ios,Objective C,Uiview,Uibutton,Parse Platform,如何更改ParsesPFLoginViewController`中注册按钮的(背景)颜色 我试过: PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init]; logInViewController.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton | PFLogInFieldsPasswordForgo
s
PFLoginViewController`中注册按钮的(背景)颜色
我试过:
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
logInViewController.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton | PFLogInFieldsPasswordForgotten | PFLogInFieldsSignUpButton ;
logInViewController.logInView.signUpButton.backgroundColor = [UIColor redColor];
这是我的结果:
如何正确设置颜色?我无法直接更改按钮的颜色。通常,我会通过
setTintColor:
完成。通过使用完成块实际更改背景图像,我可以实现更改的背景颜色,如下所示:
PFLogInViewController *login = [[PFLogInViewController alloc]init];
login.delegate = self;
[self presentViewController:login animated:YES completion:^{
[login.logInView.signUpButton setBackgroundImage:[UIImage imageNamed:@"restBtn@2x"] forState:UIControlStateNormal];
[login.logInView.signUpButton setBackgroundImage:[UIImage imageNamed:@"restBtn@2x"] forState:UIControlStateHighlighted];
}];
只需确保您已将所需的红色按钮图像包含在项目中的某个位置,以便名称解析工作正常
编辑:如Dmitry所述,为每个对您重要的UIButton控件状态配置所需的映像可能是明智的。此外,我还希望能够通过uicontrol状态集合,例如
[login.logInView.signUpButton setBackgroundImage:[UIImage imageNamed:@"restBtn@2x"] forState:UIControlStateHighlighted|UIControlStateNormal];
对于单个按钮和图像组合,但它似乎不起作用。将背景图像更改为零,然后设置按钮的背景颜色:
[logInViewController.logInView.signUpButton setBackgroundImage:nil
forState:UIControlStateNormal];
logInViewController.logInView.logInButton.backgroundColor = [UIColor redColor];
我认为您需要为所有必需的状态设置映像,而不仅仅是uicontrolStateNormal。我想我同意您的看法。我据此编辑了我的答案。感谢您调出其他控件状态。虽然有效,但底部的答案是最好的,因为它不涉及图像。回答好!非常感谢。