`
ydbc
  • 浏览: 715960 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

進階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 *viewin alertView.subviews )
  15. {
  16. //列舉alertView中所有的物件
  17. if( ![view isKindOfClass:[UILabelclass]] )
  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. }
複製代碼
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics