当图像放在按钮上时,如何设置按钮的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];
答案 0 :(得分:1)
您不应该使用setImage
作为按钮,只需使用-[UIButton setBackgroundImage: forState:]
答案 1 :(得分:1)
[startLoginBtn setImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
将其更改为
[startLoginBtn setBackgroundImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
答案 2 :(得分:1)
你也可以试试这个,
UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
[ Button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[Button addTarget:self action:@selector(YourMethodName:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:Button];
view.backgroundColor = [UIColor clearColor];
答案 3 :(得分:0)
将图像作为背景图像。
使用以下代码。
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];