简体   繁体   English

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

[英]How to set the title color of button?

How can set the title color of the button when an image is placed on button.?Any one can help me out this.. My Code for the same is mentioned below: 当将图像放置在按钮上时,如何设置按钮的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];

您不应将setImage用于按钮,而应使用-[UIButton setBackgroundImage: forState:]

[startLoginBtn setImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];

更改为

[startLoginBtn setBackgroundImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];

Also you can try this one, 你也可以试试这个

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

Put your image as background image. 将您的图像作为背景图像。

Use following code. 使用以下代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM