Home > DeveloperSection > Forums > Displaying shadow under bottom edge of UIView Controller in iOS.
Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    January-02-2016 7:41 AM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 320  View(s)
Rate this:

I want to display a shadow on UIView controller because I have a need in our iPhone application to display a shadow under the bottom edge of UIView Controller.
I have searched and found CGContextSetShadow() for drawing the shadow, but still I have getting problem:
Here is my code:

-(void)drawRect:(CGRect)rect {
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextSaveGState(context);
  CGContextSetShadow(context, CGSizeMake(-25,15),8);
  CGContextRestoreGState(context);
  [super drawRect: rect];
}

but the above code is not working.
Please tell me what is wrong in my code if any. or is any other best solution for that then please provide me the code.
Thank you.



Tarun Kumar

Total Post:210

Points:1614
Posted on    January-03-2016 10:51 PM

Any type of shadow will be affected after the code:

CGContextSetShadow(context,CGSizeMake(-25, 15), 8);

but use above code before this code:

CGContextRestoreGState(context);

here is your complete code:

-(void)drawRect:(CGRect)rect {
  CGContextRef context=UIGraphicsGetCurrentContext();
  CGContextSaveGState(context);
  CGContextSetShadow(context,CGSizeMake(-25,15),8);
  [super drawRect:rect];
  CGContextRestoreGState(context);
}

Don't want to miss updates? Please click the below button!

Follow MindStick