iOS development UI Chapter---Custom Uiactionsheet

Source: Internet
Author: User

Reprinted from: http://www.cnblogs.com/pengyingh/articles/2343200.html

Uiactionsheet class is an important class that implements warning boxes in iOS development, and in many applications it has been extended to introduce a custom style of uiactionsheet today.

First, Custom Customactionsheet class

The Customactionsheet class inherits the Uiactionsheet, and the specific implementation is as follows:

1) CustomActionSheet.h header file

#import <Foundation/Foundation.h>

@interface Customactionsheet:uiactionsheet {

uitoolbar* ToolBar;

uiview* view;

}

@property (Nonatomic,retain) uiview* view;

@property (Nonatomic,retain) uitoolbar* ToolBar;

/* Because the actionsheet is changed by adding a button to Actionsheet, so the size is related to the number of button Actionsheet

*height = 84, 134, 184, 234, 284, 334, 384, 434, 484

* If you want to use Self.view = Anotherview. Then the size of the another must also be the same size as the view

*/

-(ID) Initwithheight: (float) Height withsheettitle: (nsstring*) title;

@end

2) CUSTOMACTIONSHEET.M implementation file

#import "CustomActionSheet.h"

@implementation Customactionsheet

@synthesize view;

@synthesize ToolBar;

-(ID) Initwithheight: (float) Height withsheettitle: (nsstring*) title

{

self = [super init];

if (self)

{

int theight = height-40;

int btnnum = THEIGHT/50;

for (int i=0; i<btnnum; i++)

{

[Self addbuttonwithtitle:@ "];

}

ToolBar = [[Uitoolbar alloc] Initwithframe:cgrectmake (0, 0, 320, 44)];

Toolbar.barstyle = Uibarstyleblackopaque;

Uibarbuttonitem *titlebutton = [[Uibarbuttonitem alloc] Initwithtitle:title

Style:uibarbuttonitemstyleplain

Target:nil

Action:nil];

Uibarbuttonitem *rightbutton = [[Uibarbuttonitem alloc] initwithtitle:@ "Done"

Style:uibarbuttonitemstyledone

Target:self

Action: @selector (done)];

Uibarbuttonitem *leftbutton = [[Uibarbuttonitem alloc] initwithtitle:@ "Cancel"

Style:uibarbuttonitemstylebordered

Target:self

Action: @selector (Docancel)];

Uibarbuttonitem *fixedbutton = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemflexiblespace

Target:nil

Action:nil];

Nsarray *array = [[Nsarray alloc] initwithobjects:leftbutton,fixedbutton,titlebutton,fixedbutton,rightbutton,nil];

[ToolBar Setitems:array];

[Titlebutton release];

[LeftButton release];

[Rightbutton release];

[Fixedbutton release];

[Array release];

[Self addsubview:toolbar];

view = [[UIView alloc] Initwithframe:cgrectmake (0, height-44)];

View.backgroundcolor = [Uicolor Grouptableviewbackgroundcolor];

[Self addsubview:view];

}

return self;

}

-(void) Done

{

[Self dismisswithclickedbuttonindex:0 animated:yes];

}

-(void) Docancel

{

[Self dismisswithclickedbuttonindex:0 animated:yes];

}

-(void) dealloc

{

[View release];

[Super Dealloc];

}

@end


Second, using the custom Customactionsheet class display prompt box

#import "TestActionSheetViewController.h"

#import "CustomActionSheet.h"

@implementation Testactionsheetviewcontroller

-(Ibaction) Btndown

{

customactionsheet* sheet = [[Customactionsheet alloc] initwithheight:284.0f

withsheettitle:@ "Custom Actionsheet"];

uilabel* label = [[UILabel alloc] Initwithframe:cgrectmake (0,50, 320, 50)];

Label.text = @ "Here is the control to customize the release";

Label.backgroundcolor = [Uicolor Clearcolor];

Label.textalignment = Uitextalignmentcenter;

[Sheet.view Addsubview:label];

[Sheet ShowInView:self.view];

[Sheet release];

}

@end

The Uilabel here is an example where you can switch to your own content.

Three

iOS development UI Chapter---Custom Uiactionsheet

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.