Jayasabeen
Jayasabeen

Reputation: 136

change button label font colour and title

I want to change the button title label with a custom font colour and title. when the viewcontroller is loaded the button is displayed as customised for 1 second and then displayed as i added in interface builder

here is my code

edit_button.frame = CGRectMake(120, 40, 30, 30);
edit_button.titleLabel.text = @"";
edit_button.titleLabel.font = [UIFont fontWithName:@"FontAwesome" size:13.0f];
edit_button.titleLabel.textColor = [UIColor colorWithRed:0.278 green:0.608 blue:0.565 alpha:1];

Upvotes: 0

Views: 66

Answers (3)

Karaban
Karaban

Reputation: 151

[edit_button setTitle:@"[]" forState:UIControlStateNormal];in your viewWillAppear: method of your ViewController

[self performSelector:@selector(loadButton) withObject:nil afterDelay:1.0f];

Than implement method loadButton

-(void)loadButton
{
    edit_button.frame = CGRectMake(120, 40, 30, 30);
    [edit_button setTitle:@"TITLE" forState:UIControlStateNormal];
    edit_button.titleLabel.font = [UIFont fontWithName:@"FontAwesome" size:13.0f];
   [edit_button setTitleColor: [UIColor colorWithRed:71/255 green:155/255 blue:144/255 alpha:1 forState:UIControlStateNormal];//BE SURE TO DEVIDE BY 255]
   [self.view addSubview:edit_button]
}

Upvotes: 0

Alexey Subbotkin
Alexey Subbotkin

Reputation: 16

Try to set up button this way:

[button setTitle:@"Button title" forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:0.278 green:0.608 blue:0.565 alpha:1] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:@"FontAwesome" size:13.0f]];

Upvotes: 0

Kunal Shah
Kunal Shah

Reputation: 1121

For a UIButton, the properties of the title label are set as such:

    [edit_button setFrame:CGRectMake(x,y,width,height)];
    [edit_button setTitle:@"[]" forState:UIControlStateNormal];
    [edit_button setTitleColor:[UIColor colorWithRed:0.278 green:0.608 blue:0.565 alpha:1] forState:UIControlStateNormal];
    [edit_button.titleLabel setFont:[UIFont fontWithName:@"FontAwesome" size:13.0f]];

Upvotes: 1

Related Questions