リストを形成するために動的オブジェクトで埋められるカスタムテーブルビューがあります。セル内の画像の半分の上部にグラデーションオーバーレイを設定しようとしています。
interface.builderでレイアウトを設定しました。
以下は私の質問です:-上下にスクロールした後、グラデーションオーバーレイが毎回再描画されて単色オーバーレイになるという問題があります。誰かがこれを克服する方法を知っていますか?
ありがとう!
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
CustomTableViewCell *cell = (CustomTableViewCell* )[tableView dequeueReusableCellWithIdentifier:@"TableCellId"];
if(cell == nil){
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableCellId"];
}
UIImageView *item_image = (UIImageView *)[cell viewWithTag:@"cell_image"];
NSString *url_image = [NSString stringWithFormat:@"%@%@", URL_SERVER_HOST, item_pic];
[item_image setImageWithURL:[NSURL URLWithString:url_image]];
//Currently get called when new cell is loaded
UIView *overlay = (UIView *)[cell viewWithTag:@"cell_overlay"];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = overlay.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor], (id)[[UIColor blackColor] CGColor], nil];
[overlay.layer insertSublayer:gradient atIndex:0];
UILabel * item_name = (UILabel *)[cell viewWithTag:@"cell_name"];
item_name.text = @"test text";
return cell;
}