I'm tweaking some visual changes and noticed that when I try to set the background color of a UIButton it only sets the color outside the actual button (not inside the button itself)
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(6, 9, 50, 25);
[button setTitle:@"Select" forState:UIControlStateNormal];
button.backgroundColor = [UIColor redColor];
Does another property exist that would allow me to set the color?
To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.
In the ChangeColor() function, we call another function Change2(). This function is used to change the color of the button again.
If you are not wanting to use images, and want it to look exactly like the Rounded Rect style, try this. Just place a UIView over the UIButton, with an identical frame and auto resize mask, set the alpha to 0.3, and set the background to a color. Then use the snippet below to clip the rounded edges off the colored overlay view. Also, uncheck the 'User Interaction Enabled' checkbox in IB on the UIView to allow touch events to cascade down to the UIButton underneath.
One side effect is that your text will also be colorized.
#import <QuartzCore/QuartzCore.h>
colorizeOverlayView.layer.cornerRadius = 10.0f;
colorizeOverlayView.layer.masksToBounds = YES;
For Xamarin
var addNote = new UIButton(UIButtonType.Custom);
//addNote.SetImage(new UIImage("Images/11-x.png"), UIControlState.Normal);
addNote.SetTitle("Add Note", UIControlState.Normal);
addNote.Frame = new RectangleF(0, 0, 130, 30);
addNote.SetTitleColor(UIColor.Blue, UIControlState.Normal);
addNote.BackgroundColor = UIColor.LightGray;
addNote.Layer.CornerRadius = 10f;
addNote.Layer.BorderColor = new MonoTouch.CoreGraphics.CGColor(0f, 100f, 0f);
addNote.Layer.BorderWidth = 2f;
addNote.TouchUpInside += delegate
{
AddNote();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With