当图像放置在按钮上时,如何设置按钮的title color。任何人都可以帮我解决这个问题。
我的代码如下:

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];

最佳答案

将您的图像作为背景图像。

使用以下代码。

startLoginBtn = [[UIButton alloc]initWithFrame:CGRectMake(25, 303, 267, 40)];
[startLoginBtn setBackgroundImage:[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];

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

10-09 06:31