UISwitch、UISlider、UISegmentedControl、UIActivityIndicatorView、UIStepper、UIProgress、UIAlertView--(图)

<span style="font-family:Menlo;">
</span><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(52, 149, 175);">UIActionSheet选择框 在下面红线的地方,也有截图</p>
<span style="font-family: Menlo;">
</span>
<span style="font-family: Menlo;">
</span>
<span style="font-family: Menlo;">- (void)viewDidLoad</span>
{
    [superviewDidLoad];
    // Do any additional setup after loading the view.
    
    
    /***************************/
    /*        UISwitch         */
    /*  ===================    */
    /*         开关按键         */
    /*  ===================    */
    /***************************/
    
    
   UISwitch *swithch=[[UISwitchalloc]initWithFrame:CGRectMake(10,100,10, 10)];
    
    //设置边框颜色
    swithch.tintColor=[UIColorredColor];
    //设置开的时候的背景颜色
    swithch.onTintColor=[UIColororangeColor];
    
    //设置按键自身的颜色
    swithch.thumbTintColor=[UIColorblueColor];
    
    //添加按键响应事件
    [swithch addTarget:selfaction:@selector(switchClick:)forControlEvents:UIControlEventValueChanged];
    self.view.backgroundColor=[UIColorbrownColor];
    
    [self.viewaddSubview:swithch];
    
    
    
    /***************************/
    /*         UISlider        */
    /*  ===================    */
    /*        控制微量变化       */
    /*  ===================    */
    /***************************/
    
    
   UISlider *slider=[[UISlideralloc]initWithFrame:CGRectMake(10,150,300, 10)];
    
    //设置slider的最小值
    slider.minimumValue=0;
    //设置slider的最大值
    slider.maximumValue=5;
    //设置一开始显示时的值
    slider.value=1.5;
    
    //设置最小值轨道颜色
    slider.minimumTrackTintColor=[UIColorredColor];
    //设置最大值轨道颜色
    slider.maximumTrackTintColor=[UIColorpurpleColor];
    
    //设置最小值图片
    slider.minimumValueImage=[UIImageimageNamed:@"1.png"];
    //设置最大值图片
    slider.maximumValueImage=[UIImageimageNamed:@"1.png"];
    
    //设置按键的图片
    [slider setThumbImage:[UIImageimageNamed:@"1.png"]forState:UIControlStateNormal];
    
    //添加事件
    [slider addTarget:selfaction:@selector(sliderChange:)forControlEvents:UIControlEventValueChanged];
    
    
    
    
    [self.viewaddSubview:slider];
    
    
    /***************************/
    /*   UISegmentedControl    */
    /*  =====================  */
    /*单选按键组(类似于一排收音机按键)*/
    /*  =====================  */
    /***************************/
    
    UISegmentedControl *segMentControl=[[UISegmentedControlalloc]initWithItems:@[@"hello",@"world",[UIImageimageNamed:@"1.png"]]];
    //注意在segMentControl中的item使用数组付值时,只能使用字符串或着图片
    
    
    segMentControl.frame=CGRectMake(10,180,300, 30);
    
    //添加响应事件
    [segMentControl addTarget:selfaction:@selector(segmentedControlChange:)forControlEvents:UIControlEventValueChanged];
    
    //设置自动反弹
    segMentControl.momentary=YES;//即是按下键后自动反弹,默认为NO
    
    
    //得到当前一共有几段
   int num=segMentControl.numberOfSegments;
    
    //更改标题
    [segMentControlsetTitle:@"张三"forSegmentAtIndex:1];//数组下标
    
    //更改图片
    [segMentControl setImage:[UIImageimageNamed:@"1.png"]forSegmentAtIndex:2];
    
    //取得某一段的标题
   NSString *str=[segMentControltitleForSegmentAtIndex:1];
    //取得某一段图片
   UIImage *image=[segMentControlimageForSegmentAtIndex:2];
    
    
    //修改颜色
    segMentControl.tintColor=[UIColorredColor];
    
    //添加一段
    [segMentControl insertSegmentWithTitle:@"东方"atIndex:3animated:YES];
    
    //删除一段
    [segMentControl removeSegmentAtIndex:1animated:YES];
    
    
    [self.viewaddSubview:segMentControl];
    
    
    
    /***************************/
    /* UIActivityIndicatorView */
    /*  =====================  */
    /*         加载控件         */
    /*  =====================  */
    /***************************/
    UIActivityIndicatorView *active=[[UIActivityIndicatorViewalloc]initWithFrame:CGRectMake(10,220 , 300, 30)];
    
    
    //设置类型
    active.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhiteLarge;
    
    
    //设置颜色
    active.color=[UIColorpurpleColor];
    //开始活动
    [activestartAnimating];
    
    //停止活动
    //[active startAnimating];
    
    [self.viewaddSubview:active];
    
    
    
    /***************************/
    /*        UIStepper        */
    /*  =====================  */
    /*         步进控件         */
    /*  =====================  */
    /***************************/
    
    
    UIStepper *step=[[UIStepperalloc]initWithFrame:CGRectMake(10,260 ,300, 20)];

   UILabel *label=[[UILabelalloc]initWithFrame:CGRectMake(10,290 ,300,20)];
    label.tag=100;
   
    
    //添加事件
    [step addTarget:selfaction:@selector(stepChange:)forControlEvents:UIControlEventValueChanged];
    
    //设置最小值
    step.minimumValue=2;
    
    //设置初始值
    step.value=2;
    
    //设置最大值
    step.maximumValue=10;
    
    //设置步进值
    step.stepValue=2;
    
    //是否循环
    step.wraps=YES;//当加到十之后,再按+号,则又会回到最小值
    
    
    //还有修改图片,可以直接进UIStepper类中查看,在此不在叙述
    
    
    
    label.text=[[NSStringalloc]initWithFormat:@"%lf",step.value];
    [self.viewaddSubview:label];
    [self.viewaddSubview:step];
    
    
    
    /***************************/
    /*     UIProgressView      */
    /*  =====================  */
    /*        进度条控件         */
    /*  =====================  */
    /***************************/
    
    
   UIProgressView *progress=[[UIProgressViewalloc]initWithFrame:CGRectMake(10,320 ,300,20)];
    
    //设置类型
    progress.progressViewStyle=UIProgressViewStyleDefault;
    progress.tag=200;
    
    [NSTimerscheduledTimerWithTimeInterval:0.1target:selfselector:@selector(proChange:)userInfo:nilrepeats:YES];
    
    //进度条颜色
    progress.progressTintColor=[UIColorredColor];
    
    //设置轨道颜色
    progress.trackTintColor=[UIColorblackColor];
    
    [self.viewaddSubview:progress];
    
    
    /***************************/
    /*       UIAlertView       */
    /*  =====================  */
    /*          警告框          */
    /*  =====================  */
    /***************************/
    
    
   UIAlertView *alertView=[[UIAlertViewalloc]initWithFrame:CGRectMake(10,350 ,300,40)];
    
    
    
    [self.viewaddSubview:alertView];
    
   UIImageView *imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(10,390 ,50,40)];
    imageView.tag=300;
    [self.viewaddSubview:imageView];
    
    UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];
    btn.frame=CGRectMake(10,390 ,120,20);
    [btn setTitle:@"选中图片" forState:UIControlStateNormal];
    
    [btn addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
    [self.viewaddSubview:btn];
    
    
    
    
    
    /***************************/
    /*      UIDatePicker       */
    /*  =====================  */
    /*         时间控件         */
    /*  =====================  */
    /***************************/
//    UIDatePicker *datePicker=[[UIDatePicker alloc] initWithFrame:CGRectMake(10, 220, 300, 30)];
//    [self.view addSubview:datePicker];
    
    
    
    
    
    
    
}
-(void)btnClick:(UIButton*)btn
{
    <span style="color:#ff0000;">//选择框
   UIActionSheet *actionSheet=[[UIActionSheetalloc]initWithTitle:@"请选择图片来源" delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"相机" otherButtonTitles:@"相册",@"交卷",nil];</span>
    [actionSheetshowInView:self.view];
}
<span style="color:#cc0000;">//实现UIActionSheetDelegate协议中的方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if (buttonIndex==3)//取消按键
    {
       return;
    }
   if (buttonIndex==0)//相机
    {
        UIAlertView *alert=[[UIAlertViewalloc]initWithTitle:@"警告"message:@"没有相机" delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
        [alertshow];
    }
    //选择相册
    UIImagePickerController *ipc=[[UIImagePickerControlleralloc]init];//创建相册控制器
   if (buttonIndex==1)
    {
       
        ipc.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    }
   if (buttonIndex==2)
    {
        ipc.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }
    
    ipc.delegate=self;
    [self presentViewController:ipcanimated:YEScompletion:^{
        
        
    }];

}</span>

//实现UIImagePickerControllerDelegate协议中的方法
//选择照片响应
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
    UIImage *image=[infoobjectForKey:UIImagePickerControllerOriginalImage];//从字典中取出选中的图片
   UIImageView * imageView=(UIImageView *)[self.viewviewWithTag:300];
    imageView.image=image;
    [picker dismissViewControllerAnimated:YEScompletion:^{
        
        
    }];
}
//点击取消按键响应
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YEScompletion:^{
        
        
    }];
}



//实现UIAlertViewDelegate协议中的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if(buttonIndex==0)
    {
        UIAlertView *alert=[[UIAlertViewalloc]initWithTitle:@"警告"message:@"没有相机" delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
        [alertshow];
    }
}

-(void)proChange:(NSTimer*)time
{
    UIProgressView *pro=(UIProgressView *)[self.viewviewWithTag:200];
    [prosetProgress:pro.progress+0.01animated:YES];
   if (pro.progress>=1) {
        [timeinvalidate];
    }
}
-(void)stepChange:(UIStepper*)sender
{
   UILabel *label=(UILabel *)[self.viewviewWithTag:100];
    label.text=[[NSStringalloc]initWithFormat:@"%lf",sender.value];
}
-(void)segmentedControlChange:(UISegmentedControl*)sender
{
    NSLog(@"选中了%d",sender.selectedSegmentIndex);
    
}
-(void)sliderChange:(UISlider*)sender
{
    
}

-(void)switchClick:(UISwitch*)sender
{  staticint count=1;
   if (count)
    {
        self.view.backgroundColor=[UIColoryellowColor];
        count=0;
    }
   else
    {
         self.view.backgroundColor=[UIColorbrownColor];
         count=1;
    }
}

UISwitch、UISlider、UISegmentedControl、UIActivityIndicatorView、UIStepper、UIProgress、UIAlertView--(图)_第1张图片

UISwitch、UISlider、UISegmentedControl、UIActivityIndicatorView、UIStepper、UIProgress、UIAlertView--(图)_第2张图片

你可能感兴趣的:(UISwitch、UISlider、UISegmentedControl、UIActivityIndicatorView、UIStepper、UIProgress、UIAlertView--(图))