iphone – UIButton上的backgroundImage错误地缩放
发布时间:2020-12-14 19:52:34 所属栏目:百科 来源:网络整理
导读:当用户按下按钮然后设置宽度动画时,我试图给我的UIButton一个新的背景图像.问题是按钮没有缩放图像(我只使用视网膜图像). 点击之前: 点击后: 以及使事情发生的代码: UIImage *buttonProfileDefault = [[UIImage imageNamed:@"Profile_Button_Default"] re
当用户按下按钮然后设置宽度动画时,我试图给我的UIButton一个新的背景图像.问题是按钮没有缩放图像(我只使用视网膜图像).
点击之前: 点击后: 以及使事情发生的代码: UIImage *buttonProfileDefault = [[UIImage imageNamed:@"Profile_Button_Default"] resizableImageWithCapInsets:UIEdgeInsetsMake(3,3,3)]; [self.profileButton setBackgroundImage:buttonProfileDefault forState:UIControlStateNormal]; [self.profileButton removeConstraint:self.profileButtonConstraint]; // Animate CGRect originalFrame = self.profileButton.frame; originalFrame.size.width = 40; [UIView animateWithDuration:0.2f animations:^{ self.profileButton.frame = originalFrame; } completion:^(BOOL finished) { }]; 解决方法
试试这个代码……
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; [self.profileButton setBackgroundImage:[UIImage imageNamed:@"Profile_Button_Default"] forState:UIControlStateNormal]; [self.profileButton setBackgroundImage:[UIImage imageNamed:@"Profile_Button_Default"] forState:UIControlStateSelected]; [self.profileButton setFrame:CGRectMake(self.profileButton.frame.origin.x,self.profileButton.frame.origin.y,self.profileButton.frame.size.width + 40,self.profileButton.frame.size.height)]; [UIView commitAnimations]; 我希望这能帮到你…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |