gpt4 book ai didi

ios - 如何缩放 UIButton 的 imageView?

转载 作者:IT王子 更新时间:2023-10-29 07:31:10 25 4
gpt4 key购买 nike

我使用 [UIButton setImage:forState:] 使用图像创建了一个名为“button”的 UIButton 实例。 button.frame 大于图像的大小。

现在我想缩小这个按钮的图像。我尝试更改 button.imageView.framebutton.imageView.boundsbutton.imageView.contentMode,但似乎都无效。

谁能帮我缩放 UIButton 的 imageView?

我像这样创建了 UIButton:

UIButton *button = [[UIButton alloc] init];
[button setImage:image forState:UIControlStateNormal];

我试着像这样缩放图像:

button.imageView.contentMode = UIViewContentModeScaleAspectFit;
button.imageView.bounds = CGRectMake(0, 0, 70, 70);

还有这个:

button.imageView.contentMode = UIViewContentModeScaleAspectFit;
button.imageView.frame = CGRectMake(0, 0, 70, 70);

最佳答案

对于原发布者,这是我找到的解决方案:

commentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;

这将允许您的按钮水平缩放。还有一个垂直设置。

我花了好几个小时才弄明白(属性的命名非常不直观)所以我想分享一下。

关于ios - 如何缩放 UIButton 的 imageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1957317/

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