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