#import <UIKit/UIKit.h> @interface lpbutton:uiview@property (nonatomic,strong) ID target; @property (Nonatomic, Assign) SEL action;-(void) AddTarget: (ID) Target action: (SEL) action; @end
lpbutton.m//loopdiner////Created by yl on 15/12/8.//copyright©2015 year yl. All rights reserved.//#import ' LPButton.h ' @implementation lpbutton-(instancetype) initWithFrame: (CGRect) frame {self = [Super Initwithframe:frame]; if (self) {[self createmyview]; } return self;} -(void) Createmyview {UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @select or (tapaction)]; [Self addgesturerecognizer:tap]; }/*//or do not add tap event, call this event directly-(void) touchesended: (Nsset *) touches withevent: (Uievent *) Event {Uitouch *touche = [touche s anyobject]; Cgpoint point = [Touche locationinview:self]; if (Cgrectcontainspoint (Self.bounds, point)) {[Self.target performSelector:self.action withobject:self]; }}*/-(void) tapaction {#pragma clang diagnostic push#pragma clang diagnostic ignored "-warc-performselector-leaks" [sel F.target performSelector:self.action withobject:self]; #pragma clang diagnostic pop}-(void) AddTarget: (ID) Target action: (SEL) Action {self.target = target; Self.action = action;} @end
This is only a method, can also be implemented by means of proxies.
Inherit UIView Write custom button