[MonoTouch] Showing buttons with a different background (tip)

Nic Wise nicw at fastchicken.co.nz
Wed Oct 26 05:59:41 EDT 2011


Nice tips, BTW. But I hope you know you can do this:

public static class ExtraStuff
{
  public static void StyleItUp(this UIView theControl)
  {
     theControl.Layer.CornerRadius = 5;  theControl.Layer.BorderWidth
= 1;  theControl.Layer.BorderColor = UIColor.Gray.CGColor;
  }
}

you can then do

UIView myView = new etc;

myView.StyleItUp();

Extension methods ROCK.

On Tue, Oct 25, 2011 at 22:22, competent_tech
<xamarinforums at competent.com> wrote:
> Our application contains numerous data entry forms and, depending on the
> user's capabilities, the state of the data entry form, or the required
> status of a field, we must change the background color of the control to
> improve the user experience. Users don't appreciate it if a button looks
> like it can be pressed, but nothing happens when they do.
>
> If you have tried to change the background color for UIButtons without
> modifying the default properties, you will have discovered that the
> background color doesn't really change. Something happens in the corners,
> but that doesn't really help.
>
> The solution is to change the Button Type from the default Rounded Rect to
> Custom.
>
> Unfortunately, that change yields a square box that doesn't appear much like
> a button. The solution to this problem is to add code that adjusts the
> corners at runtime:
>
>  theControl.Layer.CornerRadius = 5;
>  theControl.Layer.BorderWidth = 1;
>  theControl.Layer.BorderColor = UIColor.Gray.CGColor;
>
> Because we want a consistent look on all of our data entry controls (we use
> buttons to popup date and picklist views rather than having the user enter
> the data directly), we have a common method that accepts a UIView parameter
> (theControl) and then apply the above code to view. This works well for
> UIButton, UITextField, and UITextView controls.
>
>
>
> --
> View this message in context: http://monotouch.2284126.n4.nabble.com/Showing-buttons-with-a-different-background-tip-tp3938318p3938318.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2


More information about the MonoTouch mailing list