Nisha Gupta
Nisha Gupta

Reputation: 275

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:

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

Upvotes: 0

Views: 115

Answers (4)

Hiren kanetiya
Hiren kanetiya

Reputation: 251

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

Upvotes: 1

Chetan Prajapati
Chetan Prajapati

Reputation: 2297

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

change it to

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

Upvotes: 1

Nghia Luong
Nghia Luong

Reputation: 790

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

Upvotes: 1

Kumar
Kumar

Reputation: 1942

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

Upvotes: 0

Related Questions