1
\$\begingroup\$

I'm trying to implement buttons into my game. I noticed iOS has the UIButton class, which I tried, but upon drawing it nothing is shown. The asset image is properly loaded, I've checked this. The SpriteBatch isn't drawing on top of the buttons either. Draw is properly being called on every frame. The button's enabled property is set to True.

The code, simplified:

private List buttons;

public void AddButtons() { UIButton b = new UIButton(UIButtonType.Custom); b.SetBackgroundImage(UIImage.FromBundle("icon.png"), UIControlState.Normal); b.Frame = new System.Drawing.RectangleF(0, 0, 256, 256); buttons.Add(b); }

public void Draw() { foreach (UIButton b in buttons) { b.Draw(b.Frame); } }

Why isn't it visible?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

At no point in the code above do you call the equivalent of addSubView:, which I think (assuming this is a UIView) should be this.AddSubView(b).

Pre-supposing Xamarin's iOS implementation works the same way that the underlying Objective-C APIs work, you would also no longer need to explicitly call the Draw method of the buttons because that will be handled by the UI Kit machinery that Xamarin's API is wrapping.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .