2016-03-28 106 views
0

我想用自定義字體顏色和標題更改按鈕標題標籤。被加載的ViewController當顯示按鈕作爲定製1秒,然後顯示爲i的界面生成器添加更改按鈕標籤的字體顏色和標題

這裏是我的代碼

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

回答

0

嘗試設置按鈕是這樣的:

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

對於一個UIButton,標題標籤的屬性被設置作爲這樣的:

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

[edit_button的setTitle:@ forState 「[]」:UIControlStateNormal];在viewWillAppear中:你的ViewController

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

方法實現方法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] 
}