我使用以下命令创建了一个名为“button”的 UIButton 实例,其中包含图像[UIButton setImage:forState:]
。 Button.frame 大于图像的大小。
现在我想缩小这个按钮的图像。我尝试改变button.imageView.frame
, button.imageView.bounds
and button.imageView.contentMode
,但一切似乎都无效。
谁能帮我扩展UIButton
的图像视图?
我创建了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;
这将允许您的按钮水平缩放。还有一个垂直设置。
我花了几个小时才弄清楚这一点(该房产的命名是very不直观)所以我想我会分享。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)