0

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:

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];
xorpower
  • 17,975
  • 51
  • 129
  • 180
Nisha Gupta
  • 275
  • 1
  • 14
  • possible duplicate of [How can I change UIButton title color?](http://stackoverflow.com/questions/2474289/how-can-i-change-uibutton-title-color) – Mayank Jain Jul 07 '15 at 06:16

4 Answers4

1

You should not use the setImage for your button, just use -[UIButton setBackgroundImage: forState:]

Nghia Luong
  • 790
  • 1
  • 6
  • 11
1
[startLoginBtn setImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];

change it to

[startLoginBtn setBackgroundImage:[UIImage imageNamed:@"SkipLogin.png"] forState:UIControlStateNormal];
Chetan Prajapati
  • 2,249
  • 19
  • 24
1

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];
Hiren kanetiya
  • 251
  • 2
  • 16
0

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];
Kumar
  • 1,882
  • 2
  • 27
  • 44
  • Hey, i am saying that instead of repeating same answer we can upvote first right answer given on question. – Kumar Jul 03 '15 at 06:01