我创建了一个viewcontroller,并使用界面构建器为视图添加了一些标签和一个按钮。
我正在尝试向视图添加圆形白色边框,因此我使用
通过代码构建视图//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]);
既不工作
答案 0 :(得分:1)
我很亲密。如果其他任何人都坚持同样的事情,那么
this.View.BringSubviewToFront(View.Subviews[0]);