本文主要是介绍[iOS]UIView添加阴影,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
UIView添加阴影
- (void)viewDidLoad {[super viewDidLoad];[self addShadowToView:_floatView withColor:[UIColor blackColor]];
}/// 添加四边阴影效果
- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {// 阴影颜色theView.layer.shadowColor = theColor.CGColor;// 阴影偏移,默认(0, -3)theView.layer.shadowOffset = CGSizeMake(0,0);// 阴影透明度,默认0theView.layer.shadowOpacity = 0.5;// 阴影半径,默认3theView.layer.shadowRadius = 5;
}
/// 添加单边阴影效果
- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {theView.layer.shadowColor = theColor.CGColor;theView.layer.shadowOffset = CGSizeMake(0,0);theView.layer.shadowOpacity = 0.5;theView.layer.shadowRadius = 5;// 单边阴影 顶边float shadowPathWidth = theView.layer.shadowRadius;CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];theView.layer.shadowPath = path.CGPath;
}
这篇关于[iOS]UIView添加阴影的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!