2017-01-01 11 views
1

이렇게 그림자를 추가하고 있습니다.오른쪽에만 그림자를 추가하는 방법은 무엇입니까?

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]; 

그러나 그림자 3면이 추가됩니다. 어떻게하면 오른쪽에 추가 할 수 있습니까? 도와주세요. 감사

답변

0

당신이해야 할 모든 top에 뷰의 경계를 인세하는 것입니다 - left-bottom하고 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

오른쪽 상단에는 10 픽셀의 그림자가 없습니다. –

+0

@AlexandreG 답변을 업데이트했습니다. 이상하게 생각합니다. 처음에 대답을했을 때 방금보고 한 문제에 직면하지 않았습니다. – dirtydanee

+0

하지만 그림자는 오른쪽 면만이 아닙니다. 위의 코드를 복사 한 다음 그림자 불투명도를 높이면 눈에 더 분명 해집니다. http://www.goloskok.com/u/image-6UQ1XEYirw.png –