向视图层添加阴影时出现问题
在我的一种观点中,我正在向视图添加阴影。问题是阴影在左侧和右侧显示空白。右边缘。我想删除这些空格。
这是我的代码:
UIView *myView = [[ISTView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 35)];
myView.backgroundColor = [UIColor greyColor];
[myView.layer setShadowOffset:CGSizeMake(0.0, 5.0)];
[myView.layer setShadowOpacity:0.8];
[myView.layer setShadowRadius:2.0];
[myView.layer setShadowColor:[UIColor blackColor].CGColor];
[self.view addSubview:myView];
[myView release];
这是我的视图的o/p:
In one of my view I am adding shadow to a view. Thing is that the shadow shows white spaces on left & right edges. I want to remove these spaces.
Here is my code:
UIView *myView = [[ISTView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 35)];
myView.backgroundColor = [UIColor greyColor];
[myView.layer setShadowOffset:CGSizeMake(0.0, 5.0)];
[myView.layer setShadowOpacity:0.8];
[myView.layer setShadowRadius:2.0];
[myView.layer setShadowColor:[UIColor blackColor].CGColor];
[self.view addSubview:myView];
[myView release];
Here is my view's o/p:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想要均匀的阴影而没有副作用,您可以在图形编辑器中绘制它,保存为 png 并将具有可拉伸图像的 UIImageView 放置在您的视图上。并且不要忘记将clipToBounds 设置为NO。
对于系统来说,在视图层次结构之上绘制缓存的现有图像比计算图层的阴影更便宜。
If you want homogenous shadow without side effects you can draw it in graphics editor, save to png and place UIImageView with stretchable image on your view. And don't forget to set clipToBounds to NO.
It would be cheaper for system to draw cached existing image above view hierarcy than calculate layer's shadow.
使用shadowPath使阴影大于视图
Use shadowPath to make the shadow larger then the view
我能想到并且正在工作的一个解决方案是将视图的框架在 X 位置和宽度上调整 2 个像素:
但这并不是一种更干净的方法。如果谁有更好的解决方案,请指导。
One solution I could think of and is working also is to adjust the view's frame by 2 pixels in X position and width:
But this is not a cleaner approach of doing this. If anyone has better solution, please guide.
试试这个,删除代码:
[myView.layer setShadowRadius:2.0];
Try this, remove the code:
[myView.layer setShadowRadius:2.0];