gpt4 book ai didi

ios - 为什么我的 detailTextLabel 会移动?

转载 作者:行者123 更新时间:2023-11-28 22:38:44 25 4
gpt4 key购买 nike

我在 UITableViewCell 的子类中使用以下代码为我的 UITableView 中未选择的单元格设置投影

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
[self applyLabelDropShadow:!highlighted];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self applyLabelDropShadow:!selected];
}

- (void)applyLabelDropShadow:(BOOL)applyDropShadow
{
self.textLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : nil;
self.textLabel.shadowOffset = CGSizeMake(0, 1);
self.detailTextLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : nil;
self.detailTextLabel.shadowOffset = CGSizeMake(0, 1);
}

这段代码来自另一个StackOverflow question通过 Mike Stead它工作正常。

然而,当该行从选中状态移动到取消选中状态时,您可以看到 detailTextLabel 稍微向下移动,这是我不希望发生的。这不会发生在单元格的 textLabel 上。

有什么想法吗?

最佳答案

尝试对非阴影使用 [UIColor clearColor] 而不是 nil:

- (void)applyLabelDropShadow:(BOOL)applyDropShadow
{
self.textLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : [UIColor clearColor];
self.textLabel.shadowOffset = CGSizeMake(0, 1);
self.detailTextLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : [UIColor clearColor];
self.detailTextLabel.shadowOffset = CGSizeMake(0,1);
}

关于ios - 为什么我的 detailTextLabel 会移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15176673/

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