Я использую метод CAGradientLayer из этого ответа , чтобы установить градиент для моих UITableViewCells.
Однако для этой таблицы я увеличил высоту ячеек с помощью tableView: heightForRowAtIndexPath :.Мой градиентный слой теперь не покрывает всю высоту ячейки, но вместо этого останавливается на исходной высоте (см. pic ).
Я попытался установить рамку слоя на границы ячейки вtableView: cellForRowAtIndexPath: но это тоже не сработало.Есть ли способ указать, что слой должен быть автоматически изменен в размерах?
Спасибо!
Код:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.colors = [NSArray arrayWithObjects:
(id)[[UIColor purpleColor] CGColor],
(id)[[UIColor redColor] CGColor],
nil];
[cell.layer insertSublayer:gradient atIndex:0];
}
cell.layer.borderWidth = 1.0;
CALayer* gradientLayer = [cell.layer.sublayers objectAtIndex:0];
DebugLog(@"cell bounds: %@", NSStringFromCGRect(cell.bounds));
gradientLayer.frame = cell.bounds;
// Configure the cell...
return cell;
}