当我使用setTitle: forState:
方法设置我的按钮标题时,会有淡出效果和淡入效果。
- (void)respondsToTextField:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
}else {
[_cancleOrConfirmButton setTitle:@"Search" forState:UIControlStateNormal];
}
}
如何解决?
答案 0 :(得分:2)
尝试使用它。
- (void)respondsToTextField:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
[UIView performWithoutAnimation:^{
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
[_cancleOrConfirmButton layoutIfNeeded];
}];
}else {
[UIView performWithoutAnimation:^{
[_cancleOrConfirmButton setTitle:@"Search" forState:UIControlStateNormal];
[_cancleOrConfirmButton layoutIfNeeded];
}];
}
}
答案 1 :(得分:0)
当您设置按钮标题时,如果不想要效果,您可以先设置titleLable.text
。
试试这个:
- (void)respondsToTextField:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
_cancleOrConfirmButton.titleLabel.text = @"Cancel";
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
}else {
_cancleOrConfirmButton.titleLabel.text = @"Search";
[_cancleOrConfirmButton setTitle:@"Search" forState:UIControlStateNormal];
}
}
答案 2 :(得分:0)
试试这个它在我的代码中工作:
if r[3]=='Device':