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

I did it this way (the methods are called in the didSelect and didDeselect delegates methods):

- (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"]];
}

I really have no idea why my first solution is not working...

于 2013-09-18T16:22:29.767 に答える