iPhone執行個體 實現彈出框視圖

來源:互聯網
上載者:User

iPhone執行個體 實現彈出框視圖是本文要介紹的內容,最近項目中需要寫複雜的表單,需要添加日期和多選框內容,所以需要彈出視圖添加相關資訊。這裡寫一個原型,用來協助同事做複雜的表單。

模仿的效果:

實現的效果:

實現步驟如下:

建立項目iphone_sprintview

建立一個繼承UIView的子類SecondView

建立一個SecondView.xib。

下面開啟SecondView.xib,做如下操作:

添加視圖

 

在iphone_sprintviewViewController中添加相應控制項的聲明。

 
  1. IBOutlet UIDatePicker *myDataPicker;   
  2. IBOutlet UIView *myView; 

控制項關聯。

相關的代碼: #import <UIKit/UIKit.h>

 
  1. #import "SecondView.h"   
  2. @interface iphone_sprintviewViewController : UIViewController {   
  3.     SecondView *mySecondView;   
  4.     IBOutlet UIDatePicker *myDataPicker;   
  5.     IBOutlet UIView *myView;   
  6. }   
  7. @property (nonatomic,retain) SecondView *mySecondView;   
  8. @property (nonatomic,retain) UIDatePicker *myDataPicker;   
  9. @property (nonatomic,retain) UIView *myView;   
  10. -(IBAction)onClickButton:(id)sender;   
  11. @end   
  12.  
  13. #import "iphone_sprintviewViewController.h"   
  14. #import <QuartzCore/QuartzCore.h>   
  15. @implementation iphone_sprintviewViewController   
  16. @synthesize mySecondView,myDataPicker,myView;   
  17. -(void) viewDidLoad   
  18. {   
  19.     self.mySecondView=[[SecondView alloc] init];   
  20.     NSArray *array =[[NSBundle mainBundle] loadNibNamed:@"SecondView"   
  21.                                                   owner:self options:nil];   
  22.     self.mySecondView=[array objectAtIndex:0];   
  23.     //將圖層的邊框設定為圓腳   
  24.     self.myView.layer.cornerRadius = 8;   
  25.     self.myView.layer.masksToBounds = YES;   
  26.     //給圖層添加一個有色邊框   
  27.     self.myView.layer.borderWidth = 8;   
  28.     self.myView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:0.5] CGColor];   
  29. }   
  30. - (void)didReceiveMemoryWarning {   
  31.     [super didReceiveMemoryWarning];   
  32. }   
  33. - (void)viewDidUnload {   
  34.     self.mySecondView=nil;   
  35.     self.myDataPicker=nil;   
  36.     self.myView=nil;   
  37. }   
  38. - (void)dealloc {   
  39.     [self.myView release];   
  40.     [self.mySecondView release];   
  41.     [self.myDataPicker release];   
  42.     [super dealloc];   
  43. }   
  44. -(IBAction)onClickButton:(id)sender   
  45. {   
  46.     if ([sender tag]==0) {   
  47.         [self.view addSubview:mySecondView];   
  48.     }else if ([sender tag]==1) {   
  49.         [mySecondView removeFromSuperview];   
  50.     }else {   
  51.         NSLog(@"==%@",self.myDataPicker.date);   
  52.         [mySecondView removeFromSuperview];   
  53.     }   
  54. }   
  55. @end 

原始碼:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.sprintview/

小結:iPhone執行個體 實現彈出框視圖的內容介紹完了,希望本文對你有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.