IOS 按钮自定义点击效果(UI Color 转换成UI Image)

来源:互联网 发布:unity3d人物动画设置 编辑:程序博客网 时间:2024/06/04 23:23
var imgsizewhite = new SizeF((float)0.5,(float)0.5);            var imageSizeRectWhite = new RectangleF(0, 0,(float)0.5,(float)0.5);            UIGraphics.BeginImageContextWithOptions(imgsizewhite, false, 0);            var contextwhite = UIGraphics.GetCurrentContext();            UIColor imgwhitecolor = UIColor.FromRGB (255, 255, 255);            contextwhite.SetFillColor(imgwhitecolor.CGColor);            contextwhite.FillRect(imageSizeRectWhite);            var imgwhite = UIGraphics.GetImageFromCurrentImageContext();            UIGraphics.EndImageContext();            var imgsizegray= new SizeF((float)0.5,(float)0.5);            var imageSizeRectgray = new RectangleF(0, 0,(float)0.5,(float)0.5);            UIGraphics.BeginImageContextWithOptions(imgsizegray, false, 0);            var contextgray = UIGraphics.GetCurrentContext();            UIColor imggraycolor = UIColor.FromRGB (245,245,245);            contextgray.SetFillColor(imggraycolor.CGColor);            contextgray.FillRect(imageSizeRectgray);            var imggray = UIGraphics.GetImageFromCurrentImageContext();            UIGraphics.EndImageContext();            btnFirst.SetBackgroundImage (imgwhite, UIControlState.Normal);            btnFirst.SetBackgroundImage (imggray, UIControlState.Highlighted);            btnSecond.SetBackgroundImage (imgwhite, UIControlState.Normal);            btnSecond.SetBackgroundImage (imggray, UIControlState.Highlighted);

注意:按钮的Type一定要设置成Custom

0 0
原创粉丝点击