2014-07-07 161 views
0

我有方法,在我的座標上創建按鈕。如何從按鈕事件獲取自定義按鈕座標?

private void DrawButtonsOnGraphics (List<Tuple<float, float>> listOfData, UIColor colorOfGraph, float radius) 
     { 
      foreach (var item in listOfData) { 
       UIButton button = new UIButton (UIButtonType.Custom); 
       button.BackgroundColor = UIColor.Black; 
       button.Frame = new RectangleF (item.Item1 - radius/2, item.Item2 - radius/2, radius, radius); 
       button.TouchUpInside += GraphicButtonClick; 
       AddSubview (button); 
      } 
     } 

而且我有處理我的點擊事件。

void GraphicButtonClick (object sender, EventArgs e) 
     {   
      if (_cliked != true) { 
       view = new UIView(new RectangleF(item.Item1 - 23,item.Item2 - 25,45,23)); 
       labelText = new UILabel(new RectangleF(10,10,30,20)); 
       labelText.Text = ((225-item.Item2)/2).ToString(); 
       labelText.TextColor = UIColor.White; 
       labelText.TextAlignment = UITextAlignment.Center; 
       view.AddSubview(labelText); 
       view.BackgroundColor = UIColor.Black; 
       AddSubview(view); 
      } 
      else { 
       view.RemoveFromSuperview(); 
      } 
     } 

我需要從我的按鈕創建子視圖上。在wpf我可以從EventArgs中獲取它。我怎麼能在iOs,xamarin中做到這一點? Thnanks

回答

0

投發件人的UIButton然後用它的框架屬性來獲取座標

UIButton btn = ((UIButton)sender); 
double x = btn.Frame.X; 
couble y = btn.Frame.Y; 
+0

ü我心目中的英雄。非常感謝 )) –