2016-11-04 2 views
0

Здесь я использую этот код, чтобы получить эффект градиента, но не получить эффект вообще.Добавление слоя CAGradient, но неспособное получить эффект градиента

CAGradientLayer *layer2 = [CAGradientLayer layer]; 

NSArray *gradientColors = [NSArray arrayWithObjects:(id)[self colorWithHexString:@"3eb79d"].CGColor,(id)[self colorWithHexString:@"3fb65c"].CGColor,(id)[self colorWithHexString:@"3cb7da"].CGColor, nil]; 

    [layer2 setColors:gradientColors]; 
    [layer2 setFrame:cell.userBackgroundView.layer.frame]; 
    [cell.userBackgroundView.layer insertSublayer:layer2 atIndex:0]; 
    cell.userBackgroundView.clipsToBounds = YES; 

ответ

1

Попробуйте

CAGradientLayer *gradient = [CAGradientLayer layer]; 
gradient.frame =cell.userBackgroundView.frame; 
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor], (id)[[UIColor blackColor] CGColor], nil]; 
[cell.userBackgroundView.layer insertSublayer:gradient atIndex:0]; 
0

Попробуйте изменить индекс подслоя от 0 до -1

[cell.userBackgroundView.layer insertSublayer:layer2 atIndex:-1]; 

Убедитесь, что ваш userBackgroundView не покрывается другой точкой зрения.

0

Использование

[layer2 setFrame:cell.userBackgroundView.bounds]; 

вместо

[layer2 setFrame:cell.userBackgroundView.layer.frame]; 

Если вы используете autoLayout, убедитесь, чтобы установить рамку в viewDidAppear или viewDidLayOutSubviews

Смежные вопросы