大家好,我正在尝试通过代码动态创建一个按钮, 但是当我运行调试器时,模拟器中没有显示该按钮。
这是我在 viewdidload 方法中编写的代码
var button = UIButton.FromType(UIButtonType.RoundedRect);
button.Frame = new System.Drawing.RectangleF(100f, 100f, 100f, 100f);
button.SetTitle("click me", UIControlState.Normal);
我也尝试了其他代码,例如:
UIButton button = new UIButton(UIButtonType.InfoDark); //BTN
button.Frame = new CoreGraphics.CGRect(59, 59, 59, 59);
我认为这个问题很愚蠢,但我找不到解决方案。 谢谢
最佳答案
你必须添加
它到你的UIView
(UIViewController
)
UIButton button = new UIButton(UIButtonType.InfoDark); //BTN
button.Frame = new CoreGraphics.CGRect(59, 59, 59, 59);
Add(button);
This is an alias for UIView.AddSubview, but uses the Add pattern as it allows C# 3.0 constructs to add subviews after creating the object.
关于c# - 以编程方式创建按钮单点触控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38413544/