Inherit UIView Write custom button

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.