如何使用渐变UIButton创build光面
创build一个像这样的button最简单的方法是什么,而不必使用.png并将其设置为背景?
CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = self.rem.bounds; gradient.cornerRadius=7.0f; gradient.colors = [NSArray arrayWithObjects: (id)[[UIColor blueColor] CGColor], (id)[[UIColor blueColor] CGColor], (id)[[UIColor whiteColor] CGColor],nil]; gradient.opacity=0.7f; [self.rem.layer insertSublayer:gradient atIndex:0]; self.rem.layer.cornerRadius=7.0f; [self.rem.layer setBorderWidth:0.50f];
试试这个并import QuartzCore
rem是UIButton
sockets
我希望这将解决您的问题
这个渐变button的常用方法。
CAGradientLayer *btnGradient = [CAGradientLayer layer]; btnGradient.frame = btn.bounds; btnGradient.colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed:102.0f / 255.0f green:102.0f / 255.0f blue:102.0f / 255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:51.0f / 255.0f green:51.0f / 255.0f blue:51.0f / 255.0f alpha:1.0f] CGColor], nil]; [btn.layer insertSublayer:btnGradient atIndex:0];