gpt4 book ai didi

ios - UIButton 背景边框问题 iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:13 25 4
gpt4 key购买 nike

我的应用程序中有一个带有背景图片的 UIButton,就是这个

enter image description here

我想让它更长一些,并在我的代码中添加了以下内容:

UIImage *backgroundButton = [UIImage imageNamed:@"Button.png"];
[backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)];

[self.loginButton setBackgroundImage:[backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

我试图设置一些边距来避免这种情况

enter image description here

如何获得与第一个按钮相同但尺寸相同的结果?在此先感谢您的支持


**编辑*****

我将把这两种方法都提供给我们的开发人员

耶稣:

[self.loginButton setBackgroundImage:[[UIImage imageNamed:@"Button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 8, 10, 8)] forState:UIControlStateNormal];

游戏大会:

UIImage *modifiedBackgroundButton = [backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[self.loginButton setBackgroundImage:[modifiedBackgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

[backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)];

我喜欢这两个答案耶稣非常精确,gameCon 使用我自己的代码来帮助我感谢大家的帮助!!!

结果: enter image description here

最佳答案

正如我们所看到的,您的拉伸(stretch)背景图像实际上没有设置 cap insets。您必须存储并处理此方法的结果(此代码实际上什么都不做):

[backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)];

所以正确的做法是:

UIImage *modifiedBackgroundButton = [backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[self.loginButton setBackgroundImage:[modifiedBackgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

关于ios - UIButton 背景边框问题 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19307844/

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