ActionSheetDataSource.h
CustomActionSheet.h
#import <UIKit/UIKit.h> #import "CustomActionSheetView.h" #import "ActionSheetDataSource.h" #import "CustomButton.h" @interface CustomActionSheet : UIViewController <UITableViewDataSource, UITableViewDelegate> { id<CustomActionSheetDelegate> delegate; ActionSheetDataSource*dataSource; // ActionsheetType TYPE; IBOutlet UITableView*tblView; } @property (nonatomic,retain)IBOutlet UITableView*tblView; @property (nonatomic,retain)id<CustomActionSheetDelegate> delegate; @property (nonatomic,retain)ActionSheetDataSource*dataSource; // @property (nonatomic)ActionsheetType TYPE; -(IBAction)actionBtnExit:(UIButton*)sender; @end
customActionsheet.m
@synthesize delegate; @synthesize dataSource; //@synthesize TYPE; @synthesize tblView;
CustomActionSheetView.h
CustomActionSheetView.m
+(void)loadActionSheetInView:(UIView*)view withDataSource:(ActionSheetDataSource*)dataSource andDelegate:(id<CustomActionSheetDelegate>)delegate { CustomActionSheet*actionSheet= [[CustomActionSheet alloc] initWithNibName:@"CustomActionSheet" bundle:nil]; [actionSheet setDelegate:delegate]; [actionSheet setDataSource:dataSource]; CGRect frame=[view frame]; frame.size.height -= 20; frame.origin =CGPointMake(frame.origin.x,frame.size.height+frame.origin.y); [[actionSheet view] setFrame:frame]; [[actionSheet tblView] reloadData]; [view addSubview:[actionSheet view]]; [UIView beginAnimations:@"RS_showKeyboardAnimation" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:0.3]; CGRect frame2=[view frame]; frame2.size.height -= 20; frame2.origin =CGPointMake(frame2.origin.x,10+frame2.origin.y); [[actionSheet view] setFrame:frame2]; [UIView commitAnimations]; }
Now you can call it all from any view, as shown below.
exampleview.h
#import "ActionSheetDataSource.h" #import "CustomActionSheet.h" <CustomActionSheetDelegate>
exampleview.m
-(void)calling { ActionSheetDataSource*dataSource=[[[ActionSheetDataSource alloc] init] autorelease];//mm [dataSource setTitle:@"I want to"]; CustomButton*cBack=[CustomButton CustomButtonWithColor:[UIColor blackColor] andTitle:@"Go Back"]; NSMutableArray *arr = [NSMutableArray arrayWithObjects:cBack ,nil]; [dataSource setOtherButtonArr:arr]; [CustomActionSheetView loadActionSheetInView:self.view withDataSource:dataSource andDelegate:self]; } -(void)didSelectedOption:(NSString*)option { if([option isEqualToString:@"Go Back"]) return; }
CustomButton.h #import
@interface CustomButton : UIButton +(CustomButton*)CustomButtonWithColor:(UIColor*)color andTitle:(NSString*)title; +(CustomButton*)CustomButtonWithColor:(UIColor*)color title:(NSString*)title andSelectedState:(BOOL)state; @end
CustomButton.m
#import "CustomButton.h" @implementation CustomButton +(CustomButton*)CustomButtonWithColor:(UIColor*)color andTitle:(NSString*)title { CustomButton*btn=[[self class] buttonWithType:UIButtonTypeCustom]; if (btn) { [btn setTitle:title forState:UIControlStateNormal]; [btn setTitleColor:color forState:UIControlStateNormal]; [btn setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; } return btn; } +(CustomButton*)CustomButtonWithColor:(UIColor*)color title:(NSString*)title andSelectedState:(BOOL)state { CustomButton*btn=[[self class] buttonWithType:UIButtonTypeCustom]; if (btn) { [btn setTitle:title forState:UIControlStateNormal]; [btn setTitleColor:color forState:UIControlStateNormal]; [btn setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; [btn setSelected:state]; } return btn; } @end
source share