Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a custom button with highlighted
    primarykey
    data
    text
    <p>I create a custom button, because I want a gradient button. so I use this code to implement it.</p> <pre><code> @implementation CustomButton - (id)initWithFrame:(CGRect)frame { if((self = [super initWithFrame:frame])){ [self setupView]; } //[self addObserver:self forKeyPath:@"highlighted" options:0 context:nil]; return self; } - (void)awakeFromNib { [self setupView]; } # pragma mark - main - (void)setupView { self.layer.cornerRadius = 10; self.layer.borderWidth = 1.0; self.layer.borderColor = [UIColor colorWithRed:167.0/255.0 green:140.0/255.0 blue:98.0/255.0 alpha:0.25].CGColor; self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowRadius = 1; [self clearHighlightView]; CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = self.layer.bounds; gradient.cornerRadius = 10; gradient.colors = [NSArray arrayWithObjects: (id)[UIColor colorWithWhite:1.0f alpha:0.4f].CGColor, (id)[UIColor colorWithWhite:1.0f alpha:0.2f].CGColor, (id)[UIColor colorWithWhite:0.75f alpha:0.2f].CGColor, (id)[UIColor colorWithWhite:0.4f alpha:0.2f].CGColor, (id)[UIColor colorWithWhite:1.0f alpha:0.4f].CGColor, nil]; // float height = gradient.frame.size.height; gradient.locations = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], [NSNumber numberWithFloat:0.5f], [NSNumber numberWithFloat:0.8f], [NSNumber numberWithFloat:1.0f], nil]; [gradient setBackgroundColor:[UIColor redColor].CGColor]; [self.layer insertSublayer:gradient atIndex:0]; } </code></pre> <p>Now the gradient has been completed. But when I press this button , there is no highlighted status on it.</p> <p>I just want when pressed its color has been deepen. Does anyone know how to implement this? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload