【发布时间】:2018-02-02 19:46:46
【问题描述】:
如何以编程方式向 uicollectionview 添加和删除以下阴影
我知道我可以更改集合视图的背景颜色,但如何影响单元格?
【问题讨论】:
标签: ios xamarin xamarin.ios uicollectionview
如何以编程方式向 uicollectionview 添加和删除以下阴影
我知道我可以更改集合视图的背景颜色,但如何影响单元格?
【问题讨论】:
标签: ios xamarin xamarin.ios uicollectionview
使用 Swift 是这样的:
let overlay = UIView()
overlay.backgroundColor = UIColor.black.withAlphaComponent(0.6)
overlay.frame = UIScreen.main.bounds
self.view.addSubview(overlay)
我对 Xamarin 的 API 了解不多,但大概看起来如下:
UIView overlay = new UIView()
overlay.BackgroundColor = UIColor(0.0, 0.0, 0.0, 0.6)
overlay.Frame = UIScreen.Main.Bounds
View.AddSubview(overlay)
【讨论】:
如果您的应用程序支持旋转,那么您必须在 Anton 的回答中添加更多内容。
旋转设备时,简单地分配 UIScreen.Main.Bounds 将不起作用。
您必须将AutoresizingMask 提供给您的叠加视图。
UIView overlay = new UIView();
overlay.BackgroundColor = UIColor(0.0, 0.0, 0.0, 0.6);
overlay.Frame = UIScreen.Main.Bounds;
overlay.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
View.AddSubview(overlay);
【讨论】: