|
说明:示范如何利用AlertView来制作系统登入的接口
CustomAlertViewViewController.h
- #import <UIKit/UIKit.h>
- //记得加入UIAlertViewDelete
- @interface CustomAlertViewViewController : UIViewController<UIAlertViewDelegate> {
- UIAlertView *myAlertView;
- }
- @property (nonatomic,retain) UIAlertView *myAlertView;
- -(IBAction) buttonPressed:(id)sender;
- @end
复制代码
CustomAlertViewViewController.m
- -(IBAction) buttonPressed:(id)sender{
- myAlertView=[[UIAlertView alloc] initWithTitle:@"系统登入" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登入",nil];
- [myAlertView show];
- [myAlertView release];
- }
- - (void)willPresentAlertView:(UIAlertView *)alertView
- {
- CGRect frame = alertView.frame;
- if( alertView==myAlertView )
- {
- frame.origin.y -= 120;
- frame.size.height += 80;
- alertView.frame = frame;
- for( UIView * view in alertView.subviews )
- {
- //列举alertView中所有的对象
- if( ![view isKindOfClass:[UILabel class]] )
- {
- //若不UILable则另行处理
- if (view.tag==1)
- {
- //处理第一个按钮,也就是 CancelButton
- CGRect btnFrame1 =CGRectMake(30, frame.size.height-65, 105, 40);
- view.frame = btnFrame1;
- } else if (view.tag==2){
- //处理第二个按钮,也就是otherButton
- CGRect btnFrame2 =CGRectMake(142, frame.size.height-65, 105, 40);
- view.frame = btnFrame2;
- }
- }
- }
- //加入自订的label及UITextFiled
- UILabel *lblaccountName=[[UILabel alloc] initWithFrame:CGRectMake( 30, 50,60, 30 )];;
- lblaccountName.text=@"账号:";
- lblaccountName.backgroundColor=[UIColor clearColor];
- lblaccountName.textColor=[UIColor whiteColor];
- UITextField *accoutName = [[UITextField alloc] initWithFrame: CGRectMake( 85, 50,160, 30 )];
- accoutName.placeholder = @"账号名称";
- accoutName.borderStyle=UITextBorderStyleRoundedRect;
- UILabel *lblaccountPassword=[[UILabel alloc] initWithFrame:CGRectMake( 30, 85,60, 30 )];;
- lblaccountPassword.text=@"密码:";
- lblaccountPassword.backgroundColor=[UIColor clearColor];
- lblaccountPassword.textColor=[UIColor whiteColor];
- UITextField *accoutPassword = [[UITextField alloc] initWithFrame: CGRectMake( 85, 85,160, 30 )];
- accoutPassword.placeholder = @"登入密码";
- accoutPassword.borderStyle=UITextBorderStyleRoundedRect;
- //输入的数据以星号显示(密码数据)
- accoutPassword.secureTextEntry=YES;
- [alertView addSubview:lblaccountName];
- [alertView addSubview:accoutName];
- [alertView addSubview:lblaccountPassword];
- [alertView addSubview:accoutPassword];
- }
- }
- - (void)dealloc {
- [myAlertView release];
- [super dealloc];
- }
复制代码
|
说明:示范如何利用AlertView来制作系统登入的接口
CustomAlertViewViewController.h
- #import <UIKit/UIKit.h>
- //记得加入UIAlertViewDelete
- @interface CustomAlertViewViewController : UIViewController<UIAlertViewDelegate> {
- UIAlertView *myAlertView;
- }
- @property (nonatomic,retain) UIAlertView *myAlertView;
- -(IBAction) buttonPressed:(id)sender;
- @end
复制代码
CustomAlertViewViewController.m
- -(IBAction) buttonPressed:(id)sender{
- myAlertView=[[UIAlertView alloc] initWithTitle:@"系统登入" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登入",nil];
- [myAlertView show];
- [myAlertView release];
- }
- - (void)willPresentAlertView:(UIAlertView *)alertView
- {
- CGRect frame = alertView.frame;
- if( alertView==myAlertView )
- {
- frame.origin.y -= 120;
- frame.size.height += 80;
- alertView.frame = frame;
- for( UIView * view in alertView.subviews )
- {
- //列举alertView中所有的对象
- if( ![view isKindOfClass:[UILabel class]] )
- {
- //若不UILable则另行处理
- if (view.tag==1)
- {
- //处理第一个按钮,也就是 CancelButton
- CGRect btnFrame1 =CGRectMake(30, frame.size.height-65, 105, 40);
- view.frame = btnFrame1;
- } else if (view.tag==2){
- //处理第二个按钮,也就是otherButton
- CGRect btnFrame2 =CGRectMake(142, frame.size.height-65, 105, 40);
- view.frame = btnFrame2;
- }
- }
- }
- //加入自订的label及UITextFiled
- UILabel *lblaccountName=[[UILabel alloc] initWithFrame:CGRectMake( 30, 50,60, 30 )];;
- lblaccountName.text=@"账号:";
- lblaccountName.backgroundColor=[UIColor clearColor];
- lblaccountName.textColor=[UIColor whiteColor];
- UITextField *accoutName = [[UITextField alloc] initWithFrame: CGRectMake( 85, 50,160, 30 )];
- accoutName.placeholder = @"账号名称";
- accoutName.borderStyle=UITextBorderStyleRoundedRect;
- UILabel *lblaccountPassword=[[UILabel alloc] initWithFrame:CGRectMake( 30, 85,60, 30 )];;
- lblaccountPassword.text=@"密码:";
- lblaccountPassword.backgroundColor=[UIColor clearColor];
- lblaccountPassword.textColor=[UIColor whiteColor];
- UITextField *accoutPassword = [[UITextField alloc] initWithFrame: CGRectMake( 85, 85,160, 30 )];
- accoutPassword.placeholder = @"登入密码";
- accoutPassword.borderStyle=UITextBorderStyleRoundedRect;
- //输入的数据以星号显示(密码数据)
- accoutPassword.secureTextEntry=YES;
- [alertView addSubview:lblaccountName];
- [alertView addSubview:accoutName];
- [alertView addSubview:lblaccountPassword];
- [alertView addSubview:accoutPassword];
- }
- }
- - (void)dealloc {
- [myAlertView release];
- [super dealloc];
- }
复制代码
| | |
| |