2013-01-19 37 views
0

我已經創建了一個viewcontroller,並使用界面構建器爲視圖添加了一些標籤和按鈕。單點觸摸設置SubView的順序

我想一個圓形的白色邊框添加到使用

//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]); 

無論工作

回答

1

我很接近。如果其他人被困在同樣的事情上,這工作

this.View.BringSubviewToFront(View.Subviews[0]);