简体   繁体   中英

Custom UIButton class, is there a was clicked event?

I'm trying to make a custom UIButton class called BubbleButton. It will perform some animations when the button is clicked and released. Are there methods that I can put in that will be called when the button is pressed or released? Such as didClicked or something like that?

There are only (really) two that you should be worried about, setSelected and setHighlighted . setHighlighted is called immediatly after the button is pressed and setSelected is called if you hold the button for like 1/2 a second. There is also a focused state but thats not really relevant. Here is an example of a UIButton I subclasssed:

-(void)drawRect:(CGRect)rect{ 
  [super drawRect:rect]; 
  //Set unhighlighted state 
  if (self.highlighted) { 
     //Set highlighted state 
 } 
} 
-(void)setHighlighted:(BOOL)highlighted { 
  [super setHighlighted:highlighted]; 
  [self setNeedsDisplay]; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM