gpt4 book ai didi

iphone - 自定义 UIButton 图片 iOS

转载 作者:可可西里 更新时间:2023-11-01 04:27:42 24 4
gpt4 key购买 nike

是否有可能有一个自定义的 UIButton,其图像只覆盖了它的一半?我想它会是这样的:

UIButton *someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setBackgroundImage:[UIImage imageNamed:@"buttonPicture"]];

/* Then there must be some property I can set that prevents the button from stretching the image?? */

.
.
.

我想要一个 50x100px 的按钮,它的上半部分只有一个 50x50px 的图像,下半部分是透明的。

我知道如何创建自定义按钮和一切。我只是想知道控制背景图像拉伸(stretch)的属性是什么。

谢谢!

最佳答案

使用

[someButton setImage:[UIImage imageNamed:@"buttonPicture"] forState: UIControlStateNormal];
someButton.imageEdgeInsets = UIEdgeInsetsMake(-50, 0, 0, 0);

关于iphone - 自定义 UIButton 图片 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11381189/

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