2014-12-01 1 views

답변

0

있는 CoreGraphics 그림자를 사용하여 [여기 이미지 설명을 입력합니다]. 그림자의 샘플 코드는 다음과 같습니다.

하나의 이미지 뷰가 viewcontroller의 전체보기에 걸쳐 있습니다.

in .h 파일 @property CGContextRef context; 그것을 잘 실행중인

#define radians(degrees) (degrees * M_PI/180) 
     -(void) JustForYouShadow 
{ 
UIImage *image=[UIImage imageNamed:@"button.jpg"]; 
UIGraphicsBeginImageContext(self.view.frame.size); 

[self.imgView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
context=UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2.0); 
    //shadow for iBeacon 
    CGSize myShadowOffset = CGSizeMake (0.9, 15); 
    CGContextSaveGState(context); 
    CGContextSetShadow (context, myShadowOffset, 10); 

    CGRect rectangle = CGRectMake(10,10,150,150); 

    CGContextTranslateCTM(context, 90, 80) ; 
    CGContextRotateCTM(context, radians(30)); 

    CGContextDrawImage(context, rectangle, image.CGImage); 
    CGContextStrokePath(context); 
    CGContextRestoreGState(context); 
//get line on image 
self.imgView.image = UIGraphicsGetImageFromCurrentImageContext(); 
[self.imgView setAlpha:1.0]; 
UIGraphicsEndImageContext(); 

} 

enter image description here

,이 시뮬레이터의 화면 스냅입니다.

+0

컨텍스트 란 무엇입니까? –

+0

정렬 그리기 영역에서 CGContextRef –

+0

그래서 Context 대신 실제로 무엇을 넣어야합니까? –

관련 문제