public override void Draw(CGRect rect) { base.Draw((CGRect)rect); if (!_Initialized) { Init((CGRect)rect); } var highlightLayer = Layer.Sublayers[1] as CAGradientLayer; if (Highlighted) { if (HighlightColor == UIColor.Blue) { highlightLayer.Colors = new CoreGraphics.CGColor[] { HighlightColor.ColorWithAlpha(0.60f).CGColor, HighlightColor.ColorWithAlpha(0.95f).CGColor }; } else { highlightLayer.Colors = new CoreGraphics.CGColor[] { HighlightColor.ColorWithAlpha(0.10f).CGColor, HighlightColor.ColorWithAlpha(0.40f).CGColor }; } } highlightLayer.Hidden = !Highlighted; }
public override void SetTitle(string title, UIControlState forState) { if (title != null) { base.SetTitle(title, forState); SetTitleShadowColor(HighlightColor.ColorWithAlpha(0.40f), UIControlState.Normal); TitleShadowOffset = new SizeF(0, -1); var textLayer = Layer.Sublayers[0]; Layer.AddSublayer(textLayer); } }
public void Initialize(RectangleF rect) { Layer.MasksToBounds = true; Layer.CornerRadius = CornerRadius; VerticalAlignment = UIControlContentVerticalAlignment.Center; var gradientFrame = rect; var shineFrame = gradientFrame; shineFrame.Y += 1; shineFrame.X += 1; shineFrame.Width -= 2; shineFrame.Height = (shineFrame.Height / 2); var shineLayer = new CAGradientLayer(); shineLayer.Frame = shineFrame; shineLayer.Colors = new MonoTouch.CoreGraphics.CGColor[] { UIColor.White.ColorWithAlpha(0.60f).CGColor, UIColor.White.ColorWithAlpha(0.10f).CGColor }; shineLayer.CornerRadius = CornerRadius - 1.5f; var backgroundLayer = new CAGradientLayer(); backgroundLayer.Frame = gradientFrame; backgroundLayer.Colors = new MonoTouch.CoreGraphics.CGColor[] { ButtonTintColor.CGColor, ButtonTintColor.CGColor }; _HighlightLayer = new CAGradientLayer(); _HighlightLayer.Frame = gradientFrame; _HighlightLayer.Colors = new MonoTouch.CoreGraphics.CGColor[] { HighlightColor.ColorWithAlpha(0.10f).CGColor, HighlightColor.ColorWithAlpha(0.60f).CGColor }; Layer.AddSublayer(backgroundLayer); Layer.AddSublayer(shineLayer); Layer.AddSublayer(_HighlightLayer); SetTitle(Caption, UIControlState.Normal); SetTitleColor(TextColor, UIControlState.Normal); _Initialized = true; }