更改UIButton标题没有淡入淡出效果?

时间:2015-10-13 03:27:56

标签: ios objective-c uibutton

当我更改UIButton的标题时,它具有这种效果,旧标题淡出,新标题淡入。我可以在没有动画的情况下更改标题吗?

[self.a setTitle:@"a" forState:UIControlStateNormal];

2 个答案:

答案 0 :(得分:1)

对于系统UIButton,使用:

[self.a layoutIfNeeded];

对于自定义UIButton,请使用:

[UIView setAnimationsEnabled:NO];
[self.a setTitle:@"a" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];

答案 1 :(得分:0)

有两种方法可以做到这一点

1.没有动画的系统按钮

- (IBAction)actionChangeButtonTitle:(id)sender
{
  [UIView setAnimationsEnabled:NO];
  [buttonTitleChange setTitle:@"title" forState:UIControlStateNormal];
  [UIView setAnimationsEnabled:YES];
  [buttonTitleChange layoutIfNeeded]; //For System Buttons
}

2.没有动画的自定义按钮

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self 
       action:@selector(actionChangeButtonTitle:)forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"Change Title" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:btn];
- (IBAction)actionChangeButtonTitle:(id)sender
{
  [btn setTitle:@"title" forState:UIControlStateNormal];
}

谢谢 - :)