Je souhaite ajouter un rayon aux coins inférieur gauche et inférieur droit d'un UIView, puis ne laisser tomber que l'ombre au bas du même UIView. Je suis passé par des solutions dans lesquelles tous les coins sont fournis avec un rayon et ensuite l'ombre. Cela fonctionne bien. Mais lorsque j'utilise UIBeizerPath pour ajouter un rayon aux coins inférieurs, la propriété shadow ne semble pas fonctionner. J'utilise Objective-C et XCode 8.1. Comment puis-je le faire?Rayon de coin inférieur et ombre uniquement en bas deUIView dans l'objectif C
L'utilisation des coins inférieurs du code ci-dessous permet d'obtenir leur rayon, mais les propriétés d'ombre ne fonctionnent pas.
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
[testView setBackgroundColor:[UIColor yellowColor]];
// shadow
testView.layer.shadowColor = [UIColor colorWithRed:156.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1.0f].CGColor;
testView.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
testView.layer.shadowRadius = 4.0f;
testView.layer.shadowOpacity = 0.5f;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0, 0.0)];
[path addLineToPoint:CGPointMake(0.0, CGRectGetHeight(testView.frame))];
[path addLineToPoint:CGPointMake(CGRectGetWidth(testView.frame), CGRectGetHeight(testView.frame))];
[path addLineToPoint:CGPointMake(CGRectGetWidth(testView.frame), 0.0)];
testView.layer.shadowPath = path.CGPath;
//bottom corners radius
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:testView.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(2.0, 2.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
testView.layer.mask = maskLayer;
Ajoutez le code et la capture d'écran pertinents avec les résultats actuels. –