gpt4 book ai didi

ios - 如何使案例优先

转载 作者:行者123 更新时间:2023-12-01 19:01:28 25 4
gpt4 key购买 nike

我有很多情况会为每种情况生成不同的图像。问题是,图像似乎在生成后便会堆叠起来。如何设置每种情况以覆盖上一张图像?

- (void)setTileValue:(NSInteger)tileValue {
_tileValue = tileValue;
self.numberLabel.text = [@(tileValue) stringValue];
UIImageView *backgroundView = [self backgroundView:[@(tileValue) intValue]];
[self.numberLabel addSubview:backgroundView];
self.value = tileValue;
}


- (UIImageView *)backgroundView:(NSUInteger)value {
switch (value) {
case 1:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]]; // light gray
case 2:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background1"]]; // gray
case 4:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background2"]]; // gark gray
case 8:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background3"]]; // red
case 16:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background4"]]; // orange
default:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
}
}

更新代码:因此,程序每次使用initWithImage创建一个新图像。我将return设置为仅现在返回UIImage。为什么此代码也不能解决问题?
- (void)setTileValue:(NSInteger)tileValue {
_tileValue = tileValue;
self.numberLabel.text = [@(tileValue) stringValue];
// UIImageView *backgroundView = [self backgroundView:[@(tileValue) intValue]];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[self tileBG:[@(tileValue) intValue]]]; [self.numberLabel addSubview:backgroundView];
self.numberLabel.backgroundColor = [self tileColorForValue:[@(tileValue) intValue]];
self.backgroundColor = [self tileColorForValue:[@(tileValue) intValue]];
self.numberLabel.textColor = [self numberColorForValue:[@(tileValue) intValue]];
self.value = tileValue;
}

- (UIColor *)defaultBackgroundColor {
return [UIColor lightGrayColor];
}

- (UIColor *)defaultNumberColor {
return [UIColor colorWithWhite:0.0 alpha:0.0];
}

- (UIImage *)tileBG:(NSUInteger)value {
switch (value) {
case 1:
return [UIImage imageNamed:@"background"]; // light gray
case 2:
return [UIImage imageNamed:@"background1"]; // gray
case 4:
return [UIImage imageNamed:@"background2"]; // gark gray
case 8:
return [UIImage imageNamed:@"background3"]; // red
case 16:
return [UIImage imageNamed:@"background4"]; // red
case 32:
return [UIImage imageNamed:@"background5"]; // red

default:
return [UIImage imageNamed:@"background"]; // red
}
}

最佳答案

请阅读我上面的评论。然后修改您的setTitleCode如下所示。

- (void)setTileValue:(NSInteger)tileValue
{
_tileValue = tileValue;
self.numberLabel.text = [@(tileValue) stringValue];
UIImageView *backgroundView = (UIImageView *)[self.numberLabel viewWithTag:1000]; // edited code to avoid warning
if (!backgroundView)
{
backgroundView = [[UIImageView alloc] initWithImage:[self tileBG:[@(tileValue) intValue]]];
backgroundView.tag = 1000;
[self.numberLabel addSubview:backgroundView];
}

backgroundView.image = [self tileBG:[@(tileValue) intValue]];
self.numberLabel.backgroundColor = [self tileColorForValue:[@(tileValue) intValue]];
self.backgroundColor = [self tileColorForValue:[@(tileValue) intValue]];
self.numberLabel.textColor = [self numberColorForValue:[@(tileValue) intValue]];
self.value = tileValue;
}

关于ios - 如何使案例优先,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22654744/

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