0

我有一个 UICollectionView,我正在使用此代码(在 UICollectionViewCell 的子类中)在选择单元格时添加边框:

- (void)isSelected{
    NSLog(@"selected");
    [self.layer setBorderColor:[UIColor colorWithRed:213.0/255.0f green:210.0/255.0f blue:199.0/255.0f alpha:1.0f].CGColor];
    [self.layer setBorderWidth:1.0f];
    [self.layer setCornerRadius:9.5f];
}

- (void)isNotSelected{
    NSLog(@"not selected");
    [self.layer setBorderColor:[UIColor clearColor].CGColor];
    [self setNeedsDisplay];
}

选择单元格时它确实有效,但取消选择时 id 无效。我可以看到两个通话的日志。

我怎样才能删除这个边框?

先感谢您

4

2 回答 2

0

我是这样做的(在 didSelect 和 didDeselect 委托方法中调用了这些方法):

- (void)isSelected{
    [self.layer setBorderColor:[UIColor colorWithRed:213.0/255.0f green:210.0/255.0f blue:199.0/255.0f alpha:1.0f].CGColor];
    [self.layer setBorderWidth:1.0f];
    [self.layer setCornerRadius:9.5f];
}

- (void)isNotSelected{
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
    [self.layer setBorderColor:[UIColor clearColor].CGColor];
    [self.layer setBorderWidth:1.0f];
    [self.layer setCornerRadius:9.5f];
    [self.imageView setImageWithURL:[NSURL URLWithString:self.imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
}

我真的不知道为什么我的第一个解决方案不起作用......

于 2013-09-18T16:22:29.767 回答
0

您是否尝试过添加子图层并在 isNotSelected 上删除它?

于 2013-09-16T14:54:52.440 回答