Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Selected State of CAGradient UIButton in iOS
    primarykey
    data
    text
    <p>Hi I have made a custom button in code using corner radius CAGradientLayer and border colour in one of my view controllers like the below:</p> <pre><code>phoneButton = [CustomButton buttonWithType:UIButtonTypeCustom]; phoneButton.frame = CGRectMake(6, 363, 99, 48); phoneButton.titleLabel.font = [UIFont fontWithName:@"Futura-Medium" size:14]; phoneButton.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0]; phoneButton.titleLabel.shadowOffset = CGSizeMake(0, 1); [phoneButton setTitle:@"Phone" forState:UIControlStateNormal]; [phoneButton addTarget:self action:@selector(phone) forControlEvents:UIControlEventTouchUpInside]; gradient = [CAGradientLayer layer]; gradient.frame = phoneButton.bounds; gradient.cornerRadius = 8; gradient.borderColor = [[UIColor whiteColor]CGColor]; gradient.borderWidth = 2.0; gradient.colors = [NSArray arrayWithObjects:(id)[[sharedManager cellGradientEnd] CGColor], (id)[[sharedManager cellGradientStart] CGColor], nil]; [phoneButton.layer insertSublayer:gradient atIndex:0]; [self.view addSubview:phoneButton]; </code></pre> <p>Now I would like to set the selected/highlighted color of the button on selection. How do I do this. I read make a UIbutton subclass and override setSelected but I dont have a clue how to do it. Here is customButton subclass.m</p> <pre><code>#import "CustomButton.h" @implementation CustomButton @synthesize sharedManager; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code sharedManager = [[MySingleton alloc]init]; } return self; } -(void) setHighlighted:(BOOL)highlighted { if(highlighted) { NSLog(@"Highlighted"); } else { NSLog(@"Not Highlighted"); } [super setHighlighted:highlighted]; } -(void) setSelected:(BOOL)selected { if(selected) { NSLog(@"Selected"); } else { NSLog(@"Not Selected"); } [super setSelected:selected]; } @end </code></pre> <p>Or just dim the button on selection would be good? I should add that the button is not in a Xib.</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.
    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