2014-01-24 28 views
4

我正在開發一個使用當前版本的Xamarin.iOS和C#的iPad應用程序,並且試圖創建一個UITableView,它只有兩個角落(右上角和右下角)四捨五入。我知道如何通過設置myTable.Layer.CornerRadius = 6f;來使所有角落四捨五入,但不知道如何只圍繞其中兩個角落。我環顧四周,但只能看到Objective-C的答案。這是我目前所擁有的:你怎麼能只圍繞Xamarin.iOS UITableView的兩個角落?

private UIView GetModalRowHeaderView2(RectangleF bounds) 
    { 
     UIView view = new UIView(bounds); 
     view.BackgroundColor = UIColor.Gray; 

     string[] tableItems = new string[] {"Item One","Item Two","Item Three"}; 

     UITableView myTable = new UITableView(new RectangleF(0, 20, bounds.Width, bounds.Height - 40), UITableViewStyle.Plain); 
     myTable.SeparatorInset = UIEdgeInsets.Zero; 
     myTable.ScrollEnabled = false; 
     myTable.Source = new TableSource(tableItems); 

     // Rounds all corners 
     myTable.Layer.CornerRadius = 6f; 

     view.Add(myTable); 

     return view; 
    } 

任何想法如何改變這隻能圍繞兩個角?

謝謝,

回答

5

您需要使用遮罩層。在我的Github回購中,我的Xamarin.iOS代碼爲rectangular view with rounded corners。你可以用它作爲開始。從代碼

摘錄:

UIBezierPath maskPath = UIBezierPath.FromRoundedRect (this.Bounds, this.eRoundedCorners, new SizeF (this.fCornerRadius, this.fCornerRadius)); 

CAShapeLayer maskLayer = new CAShapeLayer(); 
maskLayer.Frame = this.Bounds; 
maskLayer.Path = maskPath.CGPath; 

// Set the newly created shape layer as the mask for the image view's layer 
this.Layer.Mask = maskLayer; 
+0

感謝@Krumelur ...我會去看看 –