ios - 如何设置按钮的标题颜色?

标签 ios objective-c uibutton uiimage uicolor

当图像放在按钮上时,如何设置按钮的标题颜色?任何人都可以帮我解决这个问题.. 下面提到了我的代码:

startLoginBtn = [[UIButton alloc]initWithFrame:CGRectMake(25, 303, 267, 40)];
[startLoginBtn setImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
[startLoginBtn setTitle:@"Start Login" forState:UIControlStateNormal];
[startLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[startLoginBtn addTarget:self action:@selector(startLogin:) forControlEvents:UIControlEventTouchUpInside];
[startLoginBtn setEnabled:YES];
[self.view addSubview:startLoginBtn];

最佳答案

你不应该为你的按钮使用setImage,只需使用-[UIButton setBackgroundImage: forState:]

关于ios - 如何设置按钮的标题颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31181350/

相关文章:

ios - 为什么我的标签没有隐藏?

objective-c - 在 Cocoa 应用程序中是否有组织源文件的首选方式?

iphone - 保存到 CoreData - 添加到顶部

ios - 更改 UIView 按钮操作

ios - 为什么在 Xamarin IOS customrenderer 中没有准确检测到长按开始/结束?

ios - 除非您拉动刷新,否则表中的数据不会更新。 swift ios

iphone - 如何就地交换 `NSMutableDictionary` 键和值?

objective-c - 跟踪最后按下特定类型按钮的方法

ios - 如何更改启用 "glow"时使用的 UIButton "Shows Touch On Highlight"颜色?

ios - 带有 ReactiveCocoa 的 MVVM : limit the text length of a UITextField in view model