2014-07-07 115 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

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