0
回答
让自己的UIView有shadow
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

加一个有shadow的sub view, 只需要在你自定义UIView里加几行代码。

//turning off bounds clipping allows the shadow to extend beyond the rect of the view
  [self setClipsToBounds:NO];
  //the colors for the gradient.  highColor is at the top, lowColor as at the bottom
  UIColor * highColor = [UIColor colorWithWhite:1.000 alpha:1.000];
  UIColor * lowColor = [UIColor colorWithRed:0.851 green:0.859 blue:0.867 alpha:1.000];
  //The gradient, simply enough.  It is a rectangle
  CAGradientLayer * gradient = [CAGradientLayer layer];
  [gradient setFrame:[self bounds]];
  [gradient setColors:[NSArray arrayWithObjects:(id)[highColor CGColor], (id)[lowColor CGColor], nil]];
  //the rounded rect, with a corner radius of 6 points.
  //this *does* maskToBounds so that any sublayers are masked
  //this allows the gradient to appear to have rounded corners
  CALayer * roundRect = [CALayer layer];
  [roundRect setFrame:[self bounds]];
  [roundRect setCornerRadius:6.0f];
  [roundRect setMasksToBounds:YES];
  [roundRect addSublayer:gradient];
  //add the rounded rect layer underneath all other layers of the view
  [[self layer] insertSublayer:roundRect atIndex:0];
  //set the shadow on the view's layer
  [[self layer] setShadowColor:[[UIColor blackColor] CGColor]];
  [[self layer] setShadowOffset:CGSizeMake(0, 6)];
  [[self layer] setShadowOpacity:1.0];
  [[self layer] setShadowRadius:10.0];
 


原文链接:http://blog.csdn.net/favormm/article/details/6404084
<无标签>
举报
长平狐
发帖于5年前 0回/127阅
顶部