如何设置按钮的标题颜色?
How to set the title color of button?
如何在按钮上放置图像时设置按钮的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];
您的按钮不应使用 setImage
,只需使用 -[UIButton setBackgroundImage: forState:]
[startLoginBtn setImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
改为
[startLoginBtn setBackgroundImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
你也可以试试这个,
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];
如何在按钮上放置图像时设置按钮的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];
您的按钮不应使用 setImage
,只需使用 -[UIButton setBackgroundImage: forState:]
[startLoginBtn setImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
改为
[startLoginBtn setBackgroundImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
你也可以试试这个,
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];