2017-01-01 1 views
1

J'ajoute l'ombre portée comme ceci.Comment ajouter une ombre portée uniquement pour le côté droit?

vwVertical=[[UIView alloc] init]; 
[vwVertical setBackgroundColor:[UIColor whiteColor]]; 
vwVertical.translatesAutoresizingMaskIntoConstraints = NO; 
vwVertical.layer.shadowColor=[UIColor colorWithRed:32/255 green:59/255 blue:90/255 alpha:1.0].CGColor; 
vwVertical.layer.shadowOffset=CGSizeMake(5, 0); 
vwVertical.layer.shadowOpacity=0.12; 
vwVertical.layer.shadowRadius=6.5; 
[vwBlock addSubview:vwVertical]; 

Mais cela ajoute 3 ombres. Comment puis-je ajouter juste à droite. S'il vous plaît aidez-moi. Merci

Répondre

0

Tout ce que vous devez faire est pour insérer des limites sur top de la vue - left-bottom et utiliser le shadow path.

vwVertical=[[UIView alloc] init]; 
// Create edge insets 
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0, 10, 0, 0); 
// Create rect with inset and view's bounds 
CGRect shadowPathOnlyIncludingRight = UIEdgeInsetsInsetRect(vwVertical.bounds, contentInsets); 
// Apply it on the layer's shadowPath property 
vwVertical.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPathOnlyIncludingRight].CGPath; 

[vwVertical setBackgroundColor:[UIColor whiteColor]]; 
vwVertical.translatesAutoresizingMaskIntoConstraints = NO; 
vwVertical.layer.shadowColor=[UIColor colorWithRed:32/255 green:59/255 blue:90/255 alpha:1.0].CGColor; 
vwVertical.layer.shadowOffset=CGSizeMake(5, 0); 
vwVertical.layer.shadowOpacity=0.12; 
vwVertical.layer.shadowRadius=6.5; 
+0

Mais le côté droit manque d'ombre pour les 10 pixels en haut et en bas .. –

+0

@AlexandreG J'ai mis à jour ma réponse. C'est étrange, quand j'ai d'abord répondu, je n'étais pas face au problème que vous venez de signaler. – dirtydanee

+0

Mais maintenant, l'ombre n'est pas seulement pour le côté droit. J'ai copié le code ci-dessus, juste en augmentant l'opacité de l'ombre, donc c'est plus évident à l'oeil: http://www.goloskok.com/u/image-6UQ1XEYirw.png –