Traderhut Games
Traderhut Games

Reputation: 1292

Setting background color for real in Monotouch

Ok, I'm doing this:

    UIButton btReturn;

    btReturn = UIButton.FromType (UIButtonType.RoundedRect);

    btReturn.Frame = btnBounds;
    btReturn.SetTitle (Caption, UIControlState.Normal);

    btReturn.Layer.CornerRadius = 14;
    btReturn.ClipsToBounds = true;
    btReturn.TouchUpInside += touchHandler;
    btReturn.BackgroundColor = UIColor.FromRGB (0xe4, 0x96, 0x37);
    return btReturn;

Which begs the question... Why the heck is it come up as WHITE background??? I originally tried to set it to clear with a background image, but that doesn't work either...

What could be wrong?

Upvotes: 0

Views: 398

Answers (3)

Casper Skoubo
Casper Skoubo

Reputation: 310

Look here: is-it-even-possible-to-change-a-uibuttons-background-color there is an example aswell on how to create your own button, as you cannot modify the rounded button.

Upvotes: 0

Luke
Luke

Reputation: 3655

This is because the RoundedRect type of UIButton doesn't allow for any other colour background apart from white.

You'll have to use a UIButtonType.Custom to change the background colour (but you'll lose the nice rounded button and end up with a square button - you'll have to design your own fancy looking button in your favourite graphics package :)

Upvotes: 1

Venk
Venk

Reputation: 5955

Try like this,

         btReturn.BackgroundView = null;
         btReturn.BackgroundColor = UIColor.Black;

Also refer the following links,

How to change background color of UIButton in Monotouch

How to set the background color on a DialogViewController (Monotouch.Dialog)

Upvotes: 0

Related Questions