gpt4 book ai didi

ios - 如何更改 UIButton 框架以适应 IOS 中的图像?

转载 作者:行者123 更新时间:2023-11-28 17:54:08 26 4
gpt4 key购买 nike

我在 Storyboard中创建了一个带有图像的按钮。当突出显示(触摸)时,我希望此按钮用更大的图像更改图像并根据新图像调整大小。 Storyboard已设置,这是我在事件内部进行修饰的代码:

if(self.testButton.state == UIControlStateHighlighted)
{
self.testButton.frame = CGRectMake(100, 20, 120, 145);
self.testButton.contentMode = UIViewContentModeScaleAspectFill;
}
NSLog(@"End Frame: ( %f %f %f %f )", self.testButton.frame.origin.x, self.testButton.frame.origin.y, self.testButton.frame.size.width, self.testButton.frame.size.height );

但我的帧大小没有改变。我的问题

1.我可以用 Storyboard解决这个问题吗?
2.如何用代码解决这个问题?

最佳答案

将 buttonFrame 声明为实例变量并添加目标。

CGRect buttonFrame;

[self.testButton addTarget:self action:@selector(touchDown) forControlEvents:UIControlEventTouchDown];
[self.testButton addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchUpInside];
}

- (void)touchDown
{
buttonFrame = self.testButton.frame;
self.testButton.frame = CGRectMake(self.testButton.frame.origin.x, self.testButton.frame.origin.y, 120, 145);
self.testButton.contentMode = UIViewContentModeScaleAspectFill;
}

- (void)touchUp
{
self.testButton.frame = buttonFrame;
}

关于ios - 如何更改 UIButton 框架以适应 IOS 中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19726839/

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