【发布时间】:2018-02-25 01:16:13
【问题描述】:
我有 uicollectionview,每个单元格都有一个 SelectedBackgroundView 属性,只有这样的背景颜色:
SelectedBackgroundView = new UIView { BackgroundColor = UIColor.Green };
如何设置选定背景视图的宽度?我需要它是默认值的一半。
我试过了:
SelectedBackgroundView.Frame = new CGRect(SelectedBackgroundView.Frame.X, SelectedBackgroundView.Frame.Y, SelectedBackgroundView.Frame.Width / 2, SelectedBackgroundView.Frame.Height / 2);
但这只会扭曲视图
这是我放代码的地方:
[Export ("initWithFrame:")]
public PhotoCell(CGRect frame) : base(frame)
{
//BackgroundView = new UIView { BackgroundColor = UIColor.Clear };
SelectedBackgroundView = new UIView { BackgroundColor = UIColor.Green };
this.AddConstraint(NSLayoutConstraint.Create(this.SelectedBackgroundView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, this.Bounds.Height / 2));
imageView = new UIImageView(frame); // set as you want
ContentView.AddSubview(imageView);
}
【问题讨论】:
标签: ios xamarin uicollectionview