我创建了一个视图控制器,并使用界面构建器向视图添加了一些标签和一个按钮。
我正在尝试向视图添加一个圆形的白色边框,因此我正在使用代码通过代码构建一个视图
//http://spazzarama.com/2011/01/08/monotouch-uiview-with-curved-border-and-shadow/
public class WhiteRectangle:UIView
{
// Constructor used when view is defined in InterfaceBuilder
public WhiteRectangle (IntPtr handle) : base(handle)
{
this.CreateCurveAndShadow();
}
// Constructor to use when creating in code
public WhiteRectangle (System.Drawing.RectangleF frame) : base(frame)
{
this.CreateCurveAndShadow();
}
private void CreateCurveAndShadow()
{
// MasksToBounds == false allows the shadow to appear outside the UIView frame
this.Layer.MasksToBounds = false;
this.Layer.CornerRadius = 10;
this.Layer.ShadowColor = UIColor.DarkGray.CGColor;
this.Layer.ShadowOpacity = 1.0f;
this.Layer.ShadowRadius = 6.0f;
this.Layer.ShadowOffset = new System.Drawing.SizeF(0f, 3f);
}
}
在我的 ViewControllers ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var view = new WhiteRectangle(new System.Drawing.RectangleF(10, 10, 300, 300));
view.BackgroundColor = UIColor.White;
View.AddSubview (view);
}
现在我的问题是我正在创建的视图,正如您所期望的那样,它是在界面构建器中创建的视图之后添加的。是否可以设置视图的顺序?
我试过了
View.Subviews[0].SendSubviewToBack(View.Subviews[1]);
View.Subviews[1].SendSubviewToBack(View.Subviews[0]);
都不工作