Advertisement
Joze

Rounded and shadowed UINavigationBar

Feb 11th, 2012
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(void)initTableView
  2. {
  3.     //Aspecto
  4.     [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:FONDO_BARRA_INICIAL] forBarMetrics:UIBarMetricsDefault];  
  5.    
  6.     //Tabla
  7.     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;    
  8.     [self.tableView setBackgroundView:nil];
  9.     [self.tableView setBackgroundColor:RGB2UICOLOR(247.0f, 247.0f, 247.0f, 1.0f)];
  10.     [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
  11.     [self.tableView setBounces:YES];
  12.    
  13.    
  14.     CALayer *capa = [self.navigationController navigationBar].layer;
  15.     [capa setShadowColor: [[UIColor blackColor] CGColor]];
  16.     [capa setShadowOpacity:0.85f];
  17.     [capa setShadowOffset: CGSizeMake(0.0f, 1.5f)];
  18.     [capa setShadowRadius:2.0f];  
  19.     [capa setShouldRasterize:YES];
  20.  
  21.    
  22.     //Redondeamos
  23.     CGRect bounds = capa.bounds;
  24.     bounds.size.height += 10.0f;    //Para que pueda salir la sombra...
  25.     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds
  26.                                                    byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
  27.                                                          cornerRadii:CGSizeMake(10.0, 10.0)];
  28.     // Create the shape layer and set its path
  29.     CAShapeLayer *maskLayer = [CAShapeLayer layer];
  30.     maskLayer.frame = bounds;
  31.     maskLayer.path = maskPath.CGPath;
  32.    
  33.     // Set the newly created shape layer as the mask for the image view's layer
  34.     [capa addSublayer:maskLayer];
  35.     capa.mask = maskLayer;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement