Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding shadow to a UINavigationControllerer
    primarykey
    data
    text
    <p>I'm trying to add shadow to a UINavigationController. My have is based on NavController and i'm trying to add a shadow like in game centers. I have this so far. It works n a UINavigationnBar but i'm trying to get it to work throughout the entire app. </p> <pre><code>CGColorRef darkColor = [[UIColor blackColor] colorWithAlphaComponent:.5f].CGColor; CGColorRef lightColor = [UIColor clearColor].CGColor; CAGradientLayer *newShadow = [[[CAGradientLayer alloc] init] autorelease]; newShadow.frame = CGRectMake(0, 44, 320, 10); newShadow.colors = [NSArray arrayWithObjects:(id)darkColor, (id)lightColor, nil]; CALayer *superlayer = self.newShadow.superlayer; [self.newShadow removeFromSuperlayer]; [superlayer addSublayer:self.newShadow]; [self.navigationBar.layer addSublayer:superlayer]; </code></pre> <p>It works directly on a UINavigationBar but applying to a NavigationController project it fails. It builds but won't add the shadow. Any ideas?</p> <p><strong>EDIT</strong>:</p> <p>I have been trying different approaches to this. I successfully created the gradient by using a shape. </p> <pre><code>@implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { UIImage *backgroundImage; backgroundImage = [UIImage imageNamed:@"nav.png"]; [backgroundImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; CGContextRef context = UIGraphicsGetCurrentContext(); CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB(); size_t num_locations = 2; CGFloat locations[2] = { 1.0, 0.0 }; CGFloat components[8] = { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.5 }; CGGradientRef myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, num_locations); CGPoint myStartPoint, myEndPoint; myStartPoint.x = 0.0; myStartPoint.y = 0.0; myEndPoint.x = 0.0; myEndPoint.y = 54.0; CGContextDrawLinearGradient (context, myGradient, myStartPoint, myEndPoint, 1); } </code></pre> <p>I can't get the gradient below the UINavigationBar and its overlaying the image. I can't seem to get this to work. What i'm trying to do is add the same shadow Game Center has. I have tried a few different ways. All I need to do here is get this to lie underneath the UINavigationBar allowing the image to be on top and have a little part of the shadow lie on top on the UITableView so when you scroll up its above the UITableView. If you fire up Game Center you'll see exactly what i'm talking about.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload