2017-04-23 8 views
1

UIViewの左下と右下に半径を追加し、同じUIViewの下にのみ影を落としたいとします。 私は、すべてのコーナーに半径とシャドウを提供するソリューションを使いました。それはうまくいきます。しかし、UIBeizerPathを使用して半径を下隅に追加すると、シャドウプロパティが機能しないように見えます。 Objective-CとXCode 8.1を使用しています。 どうすればいいですか?ボトムコーナーObjective CのUIViewの下にある半径と影のみ

以下のコードを使用すると、コーナーの半径は小さくなりますが、シャドウプロパティは機能しません。

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; 
+0

関連するコードとスクリーンショットを現在の結果とともに追加します。 –

答えて

0

マスクはシャドウをマスキングしています。あなたは2つのビューを一方の内側に持つ必要があります。マスクを内側のビューに適用し、シャドウを外側のビューに適用します。

+0

複数のビューの代わりに複数のレイヤを使用して行うことはできますか? – coderex

+0

私はそれをこのように実装したことはありませんが、おそらくうまくいくでしょう。 –

+0

コーナー半径マスクを内側のビューに適用すると、cliptoboundsがtrueに設定され、outerviewのシャドウは表示されません!! – coderex