gpt4 book ai didi

ios - - [UIImage resizableImageWithCapInsets :] strange behavior

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:16 29 4
gpt4 key购买 nike

在我的应用程序中,我以编程方式使用简单的纯色为标签制作背景,例如:

- (UIImage*)badgeImage
{
static UIImage *image = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(30, 20), NO, 0.0f);
[RGB(231, 112, 63) setFill];
[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 30, 20) cornerRadius:10] fill];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return image;

然后我使用 -resizableImageWithCapInsets: 将此图像调整为所需大小,并将结果应用为标签背景:

CGSize someSize = MY_SIZE;
UIImage *resizableImage = [badgeImage resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 10.0f)];
UIGraphicsBeginImageContextWithOptions(someSize, NO, 0);
[resizableImage drawInRect:CGRectMake(0, 0, someSize.width, someSize.height)];
UIImage *backImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[label setFrameSize:someSize];
[label setBackgroundColor:[UIColor colorWithPatternImage:backImage]];

但这给了我奇怪的结果:enter image description here我不知道这条垂直线从哪里来,也不知道如何避免它。

最佳答案

通过将 resizableImage 放入与 label 具有相同框架的 UIImageView 解决了问题。

关于ios - - [UIImage resizableImageWithCapInsets :] strange behavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21263177/

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