【发布时间】:2014-03-28 11:02:18
【问题描述】:
我需要为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;
此代码没有得到我正在寻找的结果。
我错过了什么?
【问题讨论】:
-
我不认为直接可以这样做。您必须找到一种 hacky 方式,例如创建“阴影视图”。
-
如果我的回答有帮助,请标记为回答。