Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured it out just by creating a selected Gradient and unselected Gradient state of the button in subclass.m now it is all working great!</p> <pre><code>- (CustomButton *)buttonWithType:(UIButtonType)type { return [self buttonWithType:UIButtonTypeCustom]; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (id)initWithCoder:(NSCoder *)coder { //Call the parent implementation of initWithCoder self = [super initWithCoder:coder]; //Custom drawing methods if (self) { [self drawBackgroundLayer]; [self drawHighlightBackgroundLayer]; highlightBackgroundLayer.hidden = YES; } return self; } -(void)loadSingleton{ sharedManager = [[MySingleton alloc]init]; } - (void)layoutSubviews { // Set gradient frame (fill the whole button)) backgroundLayer.frame = self.bounds; // Set inverted gradient frame highlightBackgroundLayer.frame = self.bounds; [super layoutSubviews]; } - (void)drawBackgroundLayer { [self loadSingleton]; // Check if the property has been set already if (!backgroundLayer) { backgroundLayer = [CAGradientLayer layer]; backgroundLayer.cornerRadius = 8; backgroundLayer.borderWidth = 1.5; backgroundLayer.borderColor = [UIColor whiteColor].CGColor; backgroundLayer.colors = [NSArray arrayWithObjects:(id)[[sharedManager cellGradientEnd] CGColor], (id)[[sharedManager cellGradientStart] CGColor], nil]; // Add the gradient to the layer hierarchy [self.layer insertSublayer:backgroundLayer atIndex:0]; } } - (void)drawHighlightBackgroundLayer { [self loadSingleton]; if (!highlightBackgroundLayer) { highlightBackgroundLayer = [CAGradientLayer layer]; highlightBackgroundLayer.cornerRadius = 8; highlightBackgroundLayer.borderWidth = 1.5; highlightBackgroundLayer.borderColor = [UIColor whiteColor].CGColor; highlightBackgroundLayer.colors = [NSArray arrayWithObjects:(id)[[sharedManager cellSelectedGradientEnd] CGColor], (id)[[sharedManager cellSelectedGradientStart] CGColor], nil]; [self.layer insertSublayer:highlightBackgroundLayer atIndex:1]; } } </code></pre> <p>and setting the selected state on or off</p> <pre><code>- (void)setHighlighted:(BOOL)highlighted { NSLog(@"Selected"); // Disable implicit animation [CATransaction begin]; [CATransaction setDisableActions:YES]; // Hide/show inverted gradient highlightBackgroundLayer.hidden = !highlighted; [CATransaction commit]; [super setHighlighted:highlighted]; } </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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