Use proxy and block to write a Alertview

Source: Internet
Author: User

Agent:

MyAlertView.h: @property (nonatomic,assign) ID      Delegate ; @protocol Myalertviewdelegate <nsobject>-(void) Myalertview: (Myalertview *) Alertview Clickedbuttonatindex :(Nsinteger) Buttonindex; @end
 MYALERTVIEW.M:  
-(void ) ButtonClick: (id * Button = (UIButton * int index = (int ) Button.tag- Span style= "color: #800080;" >10 ; if ([Self. Respondstoselector: @selector (myalertview:clickedbuttonatindex:)]) {[Self. delegate myalertview:self Clickedbuttonatindex:index]; } [self disappear];}
Viewcontroller at Call:
-(void) Myalertview: (Myalertview *) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{ NSLog ( @ "buttonindex:%d", Buttonindex);}

Use BLOCK:

MyAlertView.h:
@property (nonatomic,copy)void (^buttonclick) (int);
MYALERTVIEW.M:
-(void) ButtonClick: (ID) sender{ *button = (UIButton *) sender; int index = (intten; Self.buttonclick (index); [Self disappear];}
Viewcontroller at Call:
Alertview.buttonclick = ^ (int index) { NSLog (@ "buttonindex:%d " , Buttonindex); };

Uilabel category self-adapting height

#import <UIKit/UIKit.h>@interface  UILabel (autofitsize)+ (UILabel *) Getinfolabel: ( UILabel *) Label Withtext: (NSString *) Ktext Withfont: (Uifont *) Kfont withtosize: (cgrect) krect Withbackgroundcolor: ( Uicolor *) Kbackgroundcolor; @end
#import "uilabel+autofitsize.h"//determine if the system is above IOS7 (contains IOS7)#defineBIOS7 ([[[Uidevice Currentdevice] systemversion] floatvalue] >= 7.0? Yes:no)@implementationUILabel (autofitsize)#if__iphone_os_version_max_allowed < 70000+ (UILabel *) Getinfolabel: (UILabel *) label Withtext: (NSString *) Ktext Withfont: (Uifont *) Kfont withtosize: (cgrect) krect withbackgroundcolor: (Uicolor *) kbackgroundcolor{Label.font=Kfont; Label.text=Ktext; Label.textcolor=[Uicolor Blackcolor]; Label.textalignment=Nstextalignmentcenter; Label.backgroundcolor=Kbackgroundcolor; Label.numberoflines=0; Label.linebreakmode=Nslinebreakbytruncatingtail; //Content Display Height adaptiveCgsize sizetofit =[ktext sizewithfont:font constrainedtosize:cgsizemake (Krect.size.width,10000) linebreakmode:nslinebreakbywordwrapping]; Label.frame=CGRectMake (Krect.origin.x,krect.origin.y,sizetofit.width, sizetofit.height); returnlabel;}#else+ (UILabel *) Getinfolabel: (UILabel *) label Withtext: (NSString *) Ktext Withfont: (Uifont *) Kfont withtosize: (CGRect) Krect Withbackgroundcolor: (Uicolor *) kbackgroundcolor{Label.text=Ktext; Label.font=Kfont; Label.textcolor=[Uicolor Blackcolor]; Label.textalignment=Nstextalignmentcenter; Label.backgroundcolor=Kbackgroundcolor; Label.numberoflines=0; Label.linebreakmode=Nslinebreakbytruncatingtail; //the height estimate text is about to show a few lines, and the width is defined on demand. Maxfloat can figure out exactly how highCgsize size =cgsizemake (krect.size.width,10000); Nsdictionary* Tdic =[Nsdictionary Dictionarywithobjectsandkeys:kfont,nsfontattributename,nil]; //iOS7 method, gets the size that the text needs, limits the widthCgsize ActualSize =[Ktext boundingrectwithsize:size options:nsstringdrawinguseslinefragmentorigin attributes:tdic Context:nil].    Size Label.frame=CGRectMake (Krect.origin.x,krect.origin.y,actualsize.width, actualsize.height); returnlabel;}#endif@end

Code Address: http://pan.baidu.com/s/1hqAKp3u

Use proxy and block to write a Alertview

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.