我正在尝试以编程方式创建一个UIButton。 但是,默认情况下它变成了白色(这是我的导航栏的默认颜色,我觉得这很相关)。 我希望它只是在iOS7中的Apple默认蓝色。 我已经成功更改了其默认状态的颜色,但是一旦我选择它,文本又变成了白色。 我找不到如何保持它为蓝色的方法。
请问有人能够向我解释如何以编程方式创建一个UIButton并使其表现得与我在storyboard中创建的一样吗?
目前的代码:
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancelButton.frame = CGRectMake(320 - 150, 0, 140, 40);
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
cancelButton.titleLabel.tintColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
cancelButton.titleLabel.textColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
谢谢。