CAGradiantLayer の背景を持つテーブル ビューを作成します。次に、TableViewCell でラベルを作成し、タグを付けます。スクロールした後の次のセルが表示されないという問題があります。次のセルがオーバードローされているか、UITableViewCell のサブクラスから属性を取得していないようです。しかし、その 1 つのセルの後のセルが表示されます。bgLayer を削除すると動作します。どうしてか分かりません。
これは UITableView のサブクラスです
- (void)drawRect:(CGRect)rect
{
NSArray *count = [Elements getElements];
CGFloat height = count.count * 44;
CGRect newRect = rect;
CAGradientLayer *bgLayer = [BGLayer getGreyGradient];
newRect.size.height = height;
bgLayer.frame = newRect;
[self.layer insertSublayer:bgLayer atIndex:0];
そしてこれはUITableViewCellから
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
UIView *bg = [[UIView alloc] init];
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
if(selected)
{
bg.backgroundColor = [UIColor redColor];
[self setBackgroundView:bg];
// cell mit tags von 100 - 106
for(NSInteger i=100; i<107; i++)
{
UILabel *str = (UILabel *)[self viewWithTag:i];
str.textColor = [UIColor whiteColor];
}
}
else
{
bg.backgroundColor = [UIColor clearColor];
[self setBackgroundView:bg];
for(NSInteger i=100; i<107; i++)
{
UILabel *str = (UILabel *)[self viewWithTag:i];
str.textColor = [UIColor blackColor];
}
}
[super setSelected:selected animated:animated];
手伝ってくれてありがとう