gpt4 book ai didi

iphone - UIButton 上的 backgroundImage 缩放错误

转载 作者:可可西里 更新时间:2023-11-01 03:38:17 27 4
gpt4 key购买 nike

我试图在用户按下按钮时为我的 UIButton 提供新的背景图像,然后设置宽度动画。问题是按钮不缩放图像(我只使用视网膜图像)。

点击前:

enter image description here

点击后:

enter image description here

以及让事情发生的代码:

UIImage *buttonProfileDefault = [[UIImage imageNamed:@"Profile_Button_Default"] resizableImageWithCapInsets:UIEdgeInsetsMake(3, 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];

希望对你有帮助...

关于iphone - UIButton 上的 backgroundImage 缩放错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13617286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com