第一種
- (void)normalShadow {
UIView *sv = [UIView new];
sv.frame = CGRectMake(100, 100, 200, 200);
sv.backgroundColor = [UIColor whiteColor];
sv.layer.cornerRadius = 5;
sv.layer.masksToBounds = NO;
sv.layer.shadowColor = [UIColor lightGrayColor].CGColor;
sv.layer.shadowOffset = CGSizeMake(0, 0);
sv.layer.shadowOpacity = 0.8;
sv.layer.shadowRadius = 8;
[self.view addSubview:sv];
}
第二種
- (void)shadow {
UIView *v1 = [UIView new];
v1.frame = CGRectMake(0, 0, 200, 200);
v1.backgroundColor = [UIColor whiteColor];
v1.layer.cornerRadius = 5;
v1.layer.masksToBounds = YES;
UIView *v2 = [UIView new];
v2.layer.shadowColor = [UIColor lightGrayColor].CGColor;
v2.layer.shadowOffset = CGSizeMake(0, 0);
v2.layer.shadowOpacity = 0.8;
v2.layer.shadowRadius = 8;
v2.frame = CGRectMake(100, 100, 200, 200);
[v2 addSubview:v1];
[self.view addSubview:v2];
}
第三種
- (void)LayerShadow {
CALayer *shadowLayer = [CALayer layer];
shadowLayer.shadowColor = [UIColor blackColor].CGColor;
shadowLayer.shadowOffset = CGSizeMake(0, 0);
shadowLayer.shadowOpacity = 1;
shadowLayer.shadowRadius = 10;
shadowLayer.frame = CGRectMake(100, 100, 200, 200);
UIView *sv = [UIView new];
sv.frame = CGRectMake(0, 0, 200, 200);
sv.backgroundColor = [UIColor whiteColor];
sv.layer.cornerRadius = 5;
sv.layer.masksToBounds = YES;
[self.view.layer addSublayer:shadowLayer];
[shadowLayer addSublayer:sv.layer];
}