![](/img/trans.png)
[英]How adjust the dynamically the height of a view based on height of stackview?
[英]How to adjust shadow dynamically with height of view in ios?
我加了阴影带圆角的观点corners
和它的作品。 但是,当frame
的视图改变shadow
根据图将不改变其大小。 我尝试了以下方法:
-(void)addShadow:(UIView *)view withCornerRad : (int)radius{
view.clipsToBounds = YES;
CALayer *ViewLayer = view.layer;
[ViewLayer setMasksToBounds:NO ];
ViewLayer.shadowColor = [UIColor lightGrayColor].CGColor;
ViewLayer.shadowOpacity = 1.0 ;
ViewLayer.shadowRadius = 2.0 ;
ViewLayer.shadowOffset = CGSizeMake( 0 , 0 );
ViewLayer.cornerRadius = radius;
ViewLayer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
}
根据苹果公司的视图编程指南 :
视图负责绘制内容,处理多点触控事件以及管理任何子视图的布局。
因此,您可以通过两种方式更改阴影:1.通过使用覆盖的layoutSubviews函数对UIView进行子类化,可以在其中设置新的阴影大小。 2.您可以覆盖控制器的viewDidLayoutSubviews()方法,在其中可以设置新的阴影大小。
最好的祝福!
-(void)addShadow:(UIView *)view withCornerRad : (int)radius
{
view.clipsToBounds = YES;
CALayer *ViewLayer = view.layer;
ViewLayer.shadowColor = [UIColor lightGrayColor].CGColor;
ViewLayer.shadowRadius = 10;
ViewLayer.shadowOffset = CGSizeMake(0.0f, 0.0f);
ViewLayer.shadowOpacity = 2;
ViewLayer.masksToBounds = NO;
UIEdgeInsets shadowInsets = UIEdgeInsetsMake(0, 0, 0, 0);
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:UIEdgeInsetsInsetRect(view.bounds, shadowInsets)];
ViewLayer.shadowPath = shadowPath.CGPath;
}
如果要从阴影顶部,左侧,底部,右侧尝试此操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.