iOS中AlertView添加输入框

 
 
说明:示范如何利用AlertView来制作系统登入的接口

CustomAlertViewViewController.h
  1. #import <UIKit/UIKit.h>

  2. //记得加入UIAlertViewDelete
  3. @interface CustomAlertViewViewController : UIViewController<UIAlertViewDelegate> {
  4. UIAlertView *myAlertView;
  5. }

  6. @property (nonatomic,retain) UIAlertView *myAlertView;

  7. -(IBAction) buttonPressed:(id)sender;

  8. @end
复制代码
CustomAlertViewViewController.m
  1. -(IBAction) buttonPressed:(id)sender{
  2. myAlertView=[[UIAlertView alloc] initWithTitle:@"系统登入" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登入",nil];
  3. [myAlertView show];
  4. [myAlertView release];

  5. }

  6. - (void)willPresentAlertView:(UIAlertView *)alertView
  7. {
  8. CGRect frame = alertView.frame;
  9. if( alertView==myAlertView )
  10. {
  11. frame.origin.y -= 120;
  12. frame.size.height += 80;
  13. alertView.frame = frame;
  14. for( UIView * view in alertView.subviews )
  15. {
  16. //列举alertView中所有的对象
  17. if( ![view isKindOfClass:[UILabel class]] )
  18. {
  19. //若不UILable则另行处理
  20. if (view.tag==1)
  21. {
  22. //处理第一个按钮,也就是 CancelButton
  23. CGRect btnFrame1 =CGRectMake(30, frame.size.height-65, 105, 40);
  24. view.frame = btnFrame1;

  25. } else if (view.tag==2){
  26. //处理第二个按钮,也就是otherButton
  27. CGRect btnFrame2 =CGRectMake(142, frame.size.height-65, 105, 40);
  28. view.frame = btnFrame2;
  29. }
  30. }
  31. }

  32. //加入自订的label及UITextFiled
  33. UILabel *lblaccountName=[[UILabel alloc] initWithFrame:CGRectMake( 30, 50,60, 30 )];;
  34. lblaccountName.text=@"账号:";
  35. lblaccountName.backgroundColor=[UIColor clearColor];
  36. lblaccountName.textColor=[UIColor whiteColor];

  37. UITextField *accoutName = [[UITextField alloc] initWithFrame: CGRectMake( 85, 50,160, 30 )];
  38. accoutName.placeholder = @"账号名称";
  39. accoutName.borderStyle=UITextBorderStyleRoundedRect;


  40. UILabel *lblaccountPassword=[[UILabel alloc] initWithFrame:CGRectMake( 30, 85,60, 30 )];;
  41. lblaccountPassword.text=@"密码:";
  42. lblaccountPassword.backgroundColor=[UIColor clearColor];
  43. lblaccountPassword.textColor=[UIColor whiteColor];

  44. UITextField *accoutPassword = [[UITextField alloc] initWithFrame: CGRectMake( 85, 85,160, 30 )];
  45. accoutPassword.placeholder = @"登入密码";
  46. accoutPassword.borderStyle=UITextBorderStyleRoundedRect;
  47. //输入的数据以星号显示(密码数据)
  48. accoutPassword.secureTextEntry=YES;

  49. [alertView addSubview:lblaccountName];
  50. [alertView addSubview:accoutName];
  51. [alertView addSubview:lblaccountPassword];
  52. [alertView addSubview:accoutPassword];
  53. }
  54. }

  55. - (void)dealloc {
  56. [myAlertView release];
  57. [super dealloc];
  58. }
复制代码
 
 
说明:示范如何利用AlertView来制作系统登入的接口

CustomAlertViewViewController.h
  1. #import <UIKit/UIKit.h>

  2. //记得加入UIAlertViewDelete
  3. @interface CustomAlertViewViewController : UIViewController<UIAlertViewDelegate> {
  4. UIAlertView *myAlertView;
  5. }

  6. @property (nonatomic,retain) UIAlertView *myAlertView;

  7. -(IBAction) buttonPressed:(id)sender;

  8. @end
复制代码
CustomAlertViewViewController.m
  1. -(IBAction) buttonPressed:(id)sender{
  2. myAlertView=[[UIAlertView alloc] initWithTitle:@"系统登入" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登入",nil];
  3. [myAlertView show];
  4. [myAlertView release];

  5. }

  6. - (void)willPresentAlertView:(UIAlertView *)alertView
  7. {
  8. CGRect frame = alertView.frame;
  9. if( alertView==myAlertView )
  10. {
  11. frame.origin.y -= 120;
  12. frame.size.height += 80;
  13. alertView.frame = frame;
  14. for( UIView * view in alertView.subviews )
  15. {
  16. //列举alertView中所有的对象
  17. if( ![view isKindOfClass:[UILabel class]] )
  18. {
  19. //若不UILable则另行处理
  20. if (view.tag==1)
  21. {
  22. //处理第一个按钮,也就是 CancelButton
  23. CGRect btnFrame1 =CGRectMake(30, frame.size.height-65, 105, 40);
  24. view.frame = btnFrame1;

  25. } else if (view.tag==2){
  26. //处理第二个按钮,也就是otherButton
  27. CGRect btnFrame2 =CGRectMake(142, frame.size.height-65, 105, 40);
  28. view.frame = btnFrame2;
  29. }
  30. }
  31. }

  32. //加入自订的label及UITextFiled
  33. UILabel *lblaccountName=[[UILabel alloc] initWithFrame:CGRectMake( 30, 50,60, 30 )];;
  34. lblaccountName.text=@"账号:";
  35. lblaccountName.backgroundColor=[UIColor clearColor];
  36. lblaccountName.textColor=[UIColor whiteColor];

  37. UITextField *accoutName = [[UITextField alloc] initWithFrame: CGRectMake( 85, 50,160, 30 )];
  38. accoutName.placeholder = @"账号名称";
  39. accoutName.borderStyle=UITextBorderStyleRoundedRect;


  40. UILabel *lblaccountPassword=[[UILabel alloc] initWithFrame:CGRectMake( 30, 85,60, 30 )];;
  41. lblaccountPassword.text=@"密码:";
  42. lblaccountPassword.backgroundColor=[UIColor clearColor];
  43. lblaccountPassword.textColor=[UIColor whiteColor];

  44. UITextField *accoutPassword = [[UITextField alloc] initWithFrame: CGRectMake( 85, 85,160, 30 )];
  45. accoutPassword.placeholder = @"登入密码";
  46. accoutPassword.borderStyle=UITextBorderStyleRoundedRect;
  47. //输入的数据以星号显示(密码数据)
  48. accoutPassword.secureTextEntry=YES;

  49. [alertView addSubview:lblaccountName];
  50. [alertView addSubview:accoutName];
  51. [alertView addSubview:lblaccountPassword];
  52. [alertView addSubview:accoutPassword];
  53. }
  54. }

  55. - (void)dealloc {
  56. [myAlertView release];
  57. [super dealloc];
  58. }
复制代码
 
 

 
 
说明:示范如何利用AlertView来制作系统登入的接口

CustomAlertViewViewController.h
  1. #import <UIKit/UIKit.h>

  2. //记得加入UIAlertViewDelete
  3. @interface CustomAlertViewViewController : UIViewController<UIAlertViewDelegate> {
  4. UIAlertView *myAlertView;
  5. }

  6. @property (nonatomic,retain) UIAlertView *myAlertView;

  7. -(IBAction) buttonPressed:(id)sender;

  8. @end
复制代码
CustomAlertViewViewController.m
  1. -(IBAction) buttonPressed:(id)sender{
  2. myAlertView=[[UIAlertView alloc] initWithTitle:@"系统登入" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登入",nil];
  3. [myAlertView show];
  4. [myAlertView release];

  5. }

  6. - (void)willPresentAlertView:(UIAlertView *)alertView
  7. {
  8. CGRect frame = alertView.frame;
  9. if( alertView==myAlertView )
  10. {
  11. frame.origin.y -= 120;
  12. frame.size.height += 80;
  13. alertView.frame = frame;
  14. for( UIView * view in alertView.subviews )
  15. {
  16. //列举alertView中所有的对象
  17. if( ![view isKindOfClass:[UILabel class]] )
  18. {
  19. //若不UILable则另行处理
  20. if (view.tag==1)
  21. {
  22. //处理第一个按钮,也就是 CancelButton
  23. CGRect btnFrame1 =CGRectMake(30, frame.size.height-65, 105, 40);
  24. view.frame = btnFrame1;

  25. } else if (view.tag==2){
  26. //处理第二个按钮,也就是otherButton
  27. CGRect btnFrame2 =CGRectMake(142, frame.size.height-65, 105, 40);
  28. view.frame = btnFrame2;
  29. }
  30. }
  31. }

  32. //加入自订的label及UITextFiled
  33. UILabel *lblaccountName=[[UILabel alloc] initWithFrame:CGRectMake( 30, 50,60, 30 )];;
  34. lblaccountName.text=@"账号:";
  35. lblaccountName.backgroundColor=[UIColor clearColor];
  36. lblaccountName.textColor=[UIColor whiteColor];

  37. UITextField *accoutName = [[UITextField alloc] initWithFrame: CGRectMake( 85, 50,160, 30 )];
  38. accoutName.placeholder = @"账号名称";
  39. accoutName.borderStyle=UITextBorderStyleRoundedRect;


  40. UILabel *lblaccountPassword=[[UILabel alloc] initWithFrame:CGRectMake( 30, 85,60, 30 )];;
  41. lblaccountPassword.text=@"密码:";
  42. lblaccountPassword.backgroundColor=[UIColor clearColor];
  43. lblaccountPassword.textColor=[UIColor whiteColor];

  44. UITextField *accoutPassword = [[UITextField alloc] initWithFrame: CGRectMake( 85, 85,160, 30 )];
  45. accoutPassword.placeholder = @"登入密码";
  46. accoutPassword.borderStyle=UITextBorderStyleRoundedRect;
  47. //输入的数据以星号显示(密码数据)
  48. accoutPassword.secureTextEntry=YES;

  49. [alertView addSubview:lblaccountName];
  50. [alertView addSubview:accoutName];
  51. [alertView addSubview:lblaccountPassword];
  52. [alertView addSubview:accoutPassword];
  53. }
  54. }

  55. - (void)dealloc {
  56. [myAlertView release];
  57. [super dealloc];
  58. }
复制代码
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值