[英]Shadow for UIView like the shadow of a building
我需要向UIView
添加陰影。 想象它就像是從上方看的建築物。
請看這張圖片,
我的代碼:
//creating the view
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
[view setBackgroundColor:[UIColor whiteColor]];
[[view layer] setBorderColor:[[UIColor blackColor] CGColor]];
[[view layer] setBorderWidth:1.0f];
//adding the view to viewcontroller
[self.view addSubview:view];
//adding shadow to the view
view.layer.masksToBounds = NO;
view.layer.cornerRadius = 50; // if you like rounded corners
view.layer.shadowOffset = CGSizeMake(0, 0);
view.layer.shadowRadius = 10;
view.layer.shadowOpacity = 1;
這段代碼沒有得到我想要的結果。
我想念什么?
您可以嘗試設置陰影路徑。 例如:
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(size.width * 0.33f, size.height * 0.66f)];
[path addLineToPoint:CGPointMake(size.width * 0.66f, size.height * 0.66f)];
[path addLineToPoint:CGPointMake(size.width * 1.15f, size.height * 1.15f)];
[path addLineToPoint:CGPointMake(size.width * -0.15f, size.height * 1.15f)];
imgView.layer.shadowPath = path.CGPath;
可以在這里找到詳細的教程: http : //nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.