How do I programmatically provide a glossy look to UIButtons?

后端 未结 3 1265
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 12:45

I would like to add 3D or glossy look to some iPhone UIButtons, but do so without the use of PNGs or stretchable images. I have a lot of buttons of varying shapes and sizes

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 13:16

    UIButton *button1                 =   [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 200, 40)];
    button1.backgroundColor           =   [UIColor blackColor];
    
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = button1.bounds;
    gradient.colors = [NSArray arrayWithObjects: (id)[[UIColor grayColor] CGColor],(id)[[UIColor blackColor] CGColor], nil];
    [button1.layer insertSublayer:gradient atIndex:0];
    

提交回复
热议问题