/**UISengmentedControl,段控件 - (void)viewDidLoad{ UISegmentedControl *sc = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"1",@"2",@"3", nil]]; //对象数组,可以是图片[UIImage imageNamed:@""] [self.view addSubview:sc]; [sc release]; sc.frame = CGRectMake(0, 0, 320, 30); sc.segmentedControlStyle = UISegmentedControlStyleBezeled; sc.momentary = YES;//按下是否自动弹出,默认是NO,不能连续点击 [sc addTarget:self action:@selector(sc:) forControlEvents:UIControlEventValueChanged];//数值改变触发 } - (void)sc:(UISegmentedControl *)sc{ NSLog(@"%d",sc.selectedSegmentIndex); if(2==sc.selectedSegmentIndex) [sc insertSegmentWithTitle:@"4" atIndex:2 animated:YES]; //插入一段,两种方法,还可以是图像 else if(3 == sc.selectedSegmentIndex) [sc removeSegmentAtIndex:2 animated:YES]; else [sc removeAllSegments]; } */ /**UISlider滑动条 - (void)viewDidLoad{ UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 50, 320, 0)];//高系统默认,设置也没有作用 [self.view addSubview:slider]; [slider release]; //设置slider的范围和默认值 slider.minimumValue = 0.0; slider.maximumValue = 10.0; slider.value = 5.0; [slider addTarget:self action:@selector(slider:) forControlEvents:UIControlEventValueChanged]; // slider.minimumTrackTintColor = [UIColor redColor];//左侧 // slider.maximumTrackTintColor = [UIColor yellowColor];//右侧 // slider.thumbTintColor = [UIColor blueColor];//小球 // slider.minimumValueImage = [UIImage imageNamed:@""];//在最小处添加图像,是在滚动条的左侧,最大出也可以给出 // [slider setMinimumTrackImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];//把图形压缩到滚动条上 // [slider setThumbImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];//图形添加到小按钮,注意设置的是普通状态 } - (void)slider:(UISlider *)slider{ NSLog(@"%f",slider.value); } */ /**UISwitch 开关 - (void)viewDidLoad{ UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(100, 100, 0, 0)];//大小默认,只需要控制位置 [self.view addSubview:sw]; [sw release]; sw.onTintColor = [UIColor redColor];//开之后的颜色 [sw addTarget:self action:@selector(sw:) forControlEvents:UIControlEventValueChanged];//BOOl类型,也是监控值 } - (void)sw:(UISwitch *)sw{ NSLog(@"%d",sw.on);//sw.on.BOOL值,1/0 } */ /**UIActivityIndicatorView,加载状态,继承UIView,不能加事件 - (void)viewDidLoad{ self.view.backgroundColor = [UIColor redColor]; UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];//三种状态可选,大白,小白,灰 aiv.frame = CGRectMake(100, 100, 100, 100);//位置在你给出的区域的中间 [self.view addSubview:aiv]; [aiv release]; aiv.hidesWhenStopped = NO;//默认是YES [aiv startAnimating];//开始转动 [aiv stopAnimating];//停止转动 aiv.color = [UIColor redColor];//如选择大白,则变为大红 [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;//在状态栏显示加载状态 } */ /**UIProgressView 进度条 - (void)viewDidLoad{ UIProgressView *pv = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault]; pv.frame = CGRectMake(0, 100, 320, 0); [self.view addSubview:pv]; [pv release]; //进度条0-100%; pv.progress = 0.0; //模拟进度条 pv.tag = 100; [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timer:) userInfo:nil repeats:YES]; } - (void)timer:(NSTimer *)timer{ UIProgressView *pv = (UIProgressView *)[self.view viewWithTag:100]; [pv setProgress:pv.progress+0.1 animated:YES]; if(pv.progress >= 1.0){ [timer invalidate];//计时器停止 } } */ /**UIStepper +/-号 -(void)viewDidLoad{ UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(100, 100, 100, 50) ]; [self.view addSubview:stepper]; [stepper release]; //控制数值范围与默认步长 stepper.minimumValue = 0.0; stepper.maximumValue = 10.0; stepper.stepValue = 1.0; [stepper addTarget:self action:@selector(stepper:) forControlEvents:UIControlEventValueChanged]; stepper.continuous = NO;//,默认是YES,会持续改变,中间不过度 stepper.autorepeat = NO;//默认是YES,按住只允许走一格 stepper.wraps = YES;//循环,默认是NO } -(void)stepper:(UIStepper *)stepper{ NSLog(@"%f",stepper.value); } */ /** UITextField 输入框 -(void)viewDidLoad{ UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 100, 220, 50)]; [self.view addSubview:textField]; [textField release]; textField.borderStyle = UITextBorderStyleRoundedRect;//设置边框,默认是透明无边框的 textField.returnKeyType = UIReturnKeyGo;//设置return键 textField.keyboardType = UIKeyboardTypeNumberPad;//改变呼叫出来的额键盘类型 textField.textAlignment = UITextAlignmentCenter;//对齐方式 textField.placeholder = @"请输入";//占位提示符 textField.secureTextEntry = YES;//隐藏输入,密码 textField.clearButtonMode = UITextFieldViewModeAlways;//出现清空键 textField.delegate = self;//需要到头文件写协议,然后就可以用这些方法了 } //失去键盘 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITextField *textFielf = (UITextField *)[self.view viewWithTag:150]; [textFielf resignFirstResponder];//失去焦点 } //将要开始编辑时调用,返回是YES时,才调用DidBeginEdinting -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ NSLog(@"shouldBeginEdinting"); return YES; } //已经开始编辑;因为在编辑的时候键盘弹出,会覆盖一部分,所以在这个方法中编辑改变一下位置 -(void)textFieldDidBeginEditing:(UITextField *)textField{ NSLog(@"didediting"); } -(BOOL)textFieldShouldEndEditing:(UITextField *)textField{ return YES;//在要结束的时候来调用次方法,当返回的是YES的时候调用diEnd } -(void)textFieldDidEndEditing:(UITextField *)textField{ //在结束的时候将textField还原 } -(BOOL)textFieldShouldReturn:(UITextField *)textField{ NSLog(@"return");//键盘右下脚的键 return YES; } */ /**UITextView -(void)viewDidLoad{ UITextView *tv = [[UITextView alloc]initWithFrame:CGRectMake(50, 50, 220, 200) ]; [self.view addSubview:tv]; [tv release]; } -(void)textViewDidChange:(UITExtView *)textView{ NSLog(@"%d",textView.text.length);//输入一个字符加一,可用于控制输入的字符限制 } */ /**触控手势 -(void)viewDidLoad{ [super viewDidLoad]; imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 150, 120, 120)]; imageView.image = [UIImage imageNamed:@"6.jpg"]; [self.view addSubview:imageView]; [imageView release]; imageView.userInteractionEnabled = YES; //轻触手势 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:nil]; [imageView addGestureRecognizer:tap]; [tap release]; tap.numberOfTapsRequired = 2;//次数的限制,达到次数才能触发 tap.numberOfTouchesRequired = 2;//多点触摸,达到触摸点数才能触发 //移动手势 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)]; [imageView addGestureRecognizer:pan]; [pan release]; //旋转手势 UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)]; [imageView addGestureRecognizer:rotation]; [rotation release]; //缩放手势 UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)]; [imageView addGestureRecognizer:pinch]; [pinch release]; } -(void)pinch:(UIPinchGestureRecognizer *)pinch{ imageView.bounds = CGRectMake(0, 0, imageView.bounds.size.width*pinch.scale, imageView.bounds.size.height*pinch.scale);//都是相对原始状态 pinch.scale = 1.0;//设置缩放比例还原为1; } -(void)rotation:(UIRotationGestureRecognizer *)rotation{ imageView.transform = CGAffineTransformMakeRotation(finRotation+rotation.rotation); if(rotation.state == UIGestureRecognizerStateEnded){ NSLog(@"end"); finRotation += rotation.rotation;//记录上次的位置 } } -(void)pan:(UIPanGestureRecognizer *)pan{ CGPoint point = [pan translationInView:self.view]; NSLog(@"%f %f",point.x,point.y);//以触及的点为起始点,移动的距离 imageView.center = CGPointMake(imageView.center.x+point.x, imageView.center.y+point.y);//是以原始点为坐标, [pan setTranslation:CGPointZero inView:self.view];//每次把point清空 } */