如何在文本后放置按钮?

时间:2016-10-26 08:24:24

标签: ios xamarin cross-platform

UIRelativeLayout content = new UIRelativeLayout();

cell.AddSubview(content);

content.Frame = cell.Bounds;

content.AutoresizingMask = UIViewAutoresizing.All;

content.GetLayoutParams().AddLayoutRule(LayoutRule.CenterInParent);

//content.LayoutMargins = new UIEdgeInsets(5, 5, 5, 5);


// make a UITableViewCell with a clickable button

cell.TextLabel.Text = model.Button.Description;



UIButton button = new UIButton();

button.BackgroundColor = UIColor.Orange;
                button.GetLayoutParams().AddLayoutRule(LayoutRule.CenterInParent);

button.GetLayoutParams().AddLayoutRule(LayoutRule.RightOf, content);

button.GetLayoutParams().Frame = new CoreGraphics.CGRect(LayoutParams.UNSPECIFIED, LayoutParams.UNSPECIFIED, 25, 25);

//debug.GetLayoutParams().AddLayoutRule(LayoutRule.RightOf, _view);


button.TouchUpInside += (sender, e) =>

{

 model.Button.OnClick.Execute(null);

};



content.AddSubview(button);

enter image description here

1 个答案:

答案 0 :(得分:0)

而不是:

view.Frame = new CoreGraphics.CGRect(view.Frame.Y, pos.Y, view.Frame.Width, view.Frame.Height);

使用:

view.Frame = new CoreGraphics.CGRect(pos.X, view.Frame.Y, view.Frame.Width, view.Frame.Height);

仅供参考:

您向上/向下滑动似乎应该使用Frame.XFrame.Y,除非您尝试执行UIView的对角线移动:

view.Frame = new CoreGraphics.CGRect(view.Frame.X, pos.Y, view.Frame.Width, view.Frame.Height);