iPhone开发初学
                 jopen
                 12年前
            
                    1.创建ios开发工程
打开X-code ----------Flle ----------New ----------Project ----------在ios中选择Application ----------Single View Application ----------点击next ----------在Product Name 中输入工程名HelloWord ---------- Company Idenntifier 输入com.nyist.wj ----------Class Prefix 输入WJ ---------- 然后点击next,选择创建工程所要保存文档的位置 ----------点击Create 这样一个ios开发的工程就建好了
2.工程中的文件
在X-code为我们创建的工程中,包含有 
  *.h --------包含了一些头文件信息 
   *.m-------可以在这里用代码编程 
  ViewController.xib ----可以在这里拖拉控件,以XML文件的形式存储用户界面文件 
  3.Round Rect Button 按钮的点击事件,点击出现对话框
  首先在ViewController.xib 的面板中拖入一个圆角按钮的控件,然后,最重要的是给这个按钮设置点击时间的关联事件,按住Ctrl键 用鼠标把按钮与ViewControl.h头文件进行关联 
  这样就会出现以下对话栏 
  
 这样就可以相应按钮的点击事件了 
  系统会自动在ViewControl.h生成一个OnClicktest方法 
  #import然后我们可以在ViewControl.m中编写显示的dialog 对话框@interface WJViewController : UIViewController - (IBAction)OnClicktest:(id)sender; @end 
- (IBAction)OnClicktest:(id)sender {      UIAlertView  * dialog=[[UIAlertView alloc] initWithTitle:@"请问你为什么而努力?" message:@"现在的努力是为了实现小时候吹过的牛逼!" delegate:self cancelButtonTitle:@"确定"  otherButtonTitles:@"取消", nil];      [dialog show];  }效果如下:
 4.Lable标签的使用
按住Ctrl键 用鼠标把lable标签、textField 、Button与ViewControl.h头文件进行关联
 然后在Button按钮中设置的事件关联中写入如下代码 
  - (IBAction)ChageLable:(id)sender {            mylable.text=[NSString stringWithFormat:@"Button改变标签的内容来自\n%@",mytextField.text];              }这样就可以获取输入框里的内容,并赋值给标签
效果如下 
  
 5.UIAlertView的几种不同的对话框的形式
1.形式1
 实现的代码如下 
  
  //dialog 方法一 UIAlertView * dialog=[[UIAlertView alloc] initWithTitle:@"请问你为什么而努力?" message:@"现在的努力是为了实现小时候吹过的牛逼!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [dialog show];
2.形式2调用输入的数字键盘
 实现的代码如下 
  
  //dialog 方法二 UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"请问你为什么而努力?" message:@"现在的努力是为了实现小时候吹过的牛逼!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput]; //// 调用数字输入键 UITextField *textField = [dialog textFieldAtIndex:0]; textField.keyboardType = UIKeyboardTypeNumberPad; [dialog show];
3.形式3输入用户名和密码
dialog setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
 实现的代码如下 
  //dialog 方法二 UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"请问你为什么而努力?" message:@"现在的努力是为了实现小时候吹过的牛逼!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput]; //// 调用数字输入键 // UITextField *textField = [dialog textFieldAtIndex:0]; // textField.keyboardType = UIKeyboardTypeNumberPad; [dialog setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput]; [dialog show];
6.UISwitch开关控件的使用
使用开关控件控制界面颜色的改变,设置好关联后,在action中输入一下代码
- (IBAction)SwitchClick:(UISwitch *)sender {      NSLog(@"Sender is=%@",sender);      if ([sender isOn]) {          NSLog(@"开关是开启的状态");          self.view.backgroundColor = [UIColor whiteColor];      }else {          NSLog(@"开关是关闭的状态");          self.view.backgroundColor = [UIColor redColor];      }        }效果如下:


7.UIDatePicker的使用绑定数据
使用日期组件获取设置的时间,首先设置好关联Action事件后,添加如下代码就可以获取设置的日期
- (IBAction)DatePickerClick:(UIDatePicker *)sender {            if ([sender isEqual:self.myDataPicker]) {          NSLog(@"Selected date = %@", sender.date);          timeLable.text=[NSString stringWithFormat:@"设置的时间是:%@",sender.date];       }                  }实现的效果如下:   
8.Slider 滑动条的使用
设置好关联后的事件代码如下:- (IBAction)SliderClick:(UISlider *)sender {            if ([sender isEqual:self.slidername]) {          NSLog(@"设置的值为:%f",sender.value);          sliderText.text=[NSString stringWithFormat:@"改变的值为:%f",sender.value];      }  }实现的效果如下:

9.Segmented Control 分段控件的使用
- (IBAction)SegmentClick:(UISegmentedControl *)sender {            if ([sender isEqual:self.segmentname]) {          NSInteger selectIndex=[sender selectedSegmentIndex];          NSString *Selecttext=[sender titleForSegmentAtIndex:selectIndex];          NSLog(@"选择的分段%ld内容是:%@",(long)selectIndex,Selecttext);          sliderText.text=[NSString stringWithFormat:@"选择的分段%ld内容是:%@",(long)selectIndex ,Selecttext];      }        }效果图如下: 
 10.ImageView 的使用
拖入一个ImageView控件后,然后在属性中选择需要填充的图片之源,效果如下: 
  
 11.通过触摸背景关闭键盘
通过触摸背景关闭软键盘的输入方法如下: 
  需要在Viewcontroller.h中添加触碰背景的处理事件代码如下: 
  -(IBAction)backgroundEditing :(id)sender;
然后在Viewcontroller.m中为编辑框输入时候触碰背景的实现的如下
-(IBAction)backgroundEditing :(id)sender{      [username resignFirstResponder];      }然后呢,需要选中Viewcontroller.xib Alt+window+3 使他继承UIControl
 然后Alt+window+6 连接SentEvents中的Touch Down  与File‘s  Owner    选择backgroundedit  
  
 
 这样就可以实现在触碰背景的时候关闭键盘了 
    
  }
</div>