美文网首页
UIViewController

UIViewController

作者: Sherry宇 | 来源:发表于2016-02-24 10:08 被阅读0次

    UIControl 控制类

    addTarget:forcontrolEvents:添加响应事件(满足什么条件下 让某人调用什么方法)

    UISegegmentedControl(分段控制器)

    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"电话",@"微信"]];

    seg.frame=CGRectMake(100,50,200,40);

    [self.viewaddSubview:seg];

    [segrelease];

    选中分段下标

    seg.selectedSegmentIndex=0;//(从0开始)

    背景颜色

    seg.backgroundColor = [UIColor blackColor];

    渲染颜色

    seg.tintColor= [UIColorlightGrayColor];

    插入新的分段

    [seg insertSegmentWithTitle:@"陌陌" atIndex:2 animated:YES];

    添加响应事件(通过下标值得变化触发方法)

    [segaddTarget:selfaction:@selector(segAction:) forControlEvents:UIControlEventValueChanged];

    两个页面

    self.redView= [[UIViewalloc]initWithFrame:CGRectMake(40,160,250,250)];

    self.redView.backgroundColor=[UIColorredColor];

    [self.viewaddSubview:self.redView];

    [_redViewrelease];

    green

    self.greenView= [[UIViewalloc]initWithFrame:CGRectMake(40,160,250,250)];

    self.greenView.backgroundColor=[UIColoryellowColor];

    [self.viewaddSubview:self.greenView];

    [_greenViewrelease];

    /******** UISilder滑块控制器*********/

    UISlider*sl = [[UISlideralloc]initWithFrame:CGRectMake(50,420,250,50)];

    sl.backgroundColor= [UIColororangeColor];

    [self.viewaddSubview:sl];

    [slrelease];

    颜色设置

    划过距离的颜色

    sl.minimumTrackTintColor= [UIColorcyanColor];

    为划过距离的颜色(滑块右)

    sl.maximumTrackTintColor= [UIColorblueColor];

    滑块颜色

    sl.thumbTintColor= [UIColorlightGrayColor];

    添加响应事件

    [sladdTarget:selfaction:@selector(slideAction:) forControlEvents:UIControlEventValueChanged];

    滑动范围

    最小值

    sl.minimumValue= -100;

    最大值

    sl.maximumValue=1000;

    更新滑块起始点

    sl.value= -100;

    /************ UIPageControl页码控制器************/

    UIPageControl*pc = [[UIPageControlalloc]initWithFrame:CGRectMake(50,100,100,50)];

    pc.backgroundColor= [UIColorblackColor];

    [self.viewaddSubview:pc];

    [pcrelease];

    //页数

    pc.numberOfPages=4;

    //当前页

    pc.currentPage=3;

    //颜色(小点)

    pc.pageIndicatorTintColor= [UIColorredColor];

    //当前页颜色

    pc.currentPageIndicatorTintColor= [UIColoryellowColor];

    //响应事件

    [pcaddTarget:selfaction:@selector(pageAction:)forControlEvents:UIControlEventValueChanged];

    /************ UISwitch开关控制器************/

    UISwitch*sw = [[UISwitchalloc]initWithFrame:CGRectMake(200,110,100,50)];

    sw.backgroundColor= [UIColorwhiteColor];

    [self.viewaddSubview:sw];

    [swrelease];

    //开关属性

    sw.on=YES;

    //开启时颜色

    sw.onTintColor= [UIColorlightGrayColor];

    //关闭时颜色

    sw.tintColor= [UIColorcyanColor];

    //按钮颜色

    sw.thumbTintColor= [UIColorbrownColor];

    //响应方法

    [swaddTarget:selfaction:@selector(swAction:) forControlEvents:UIControlEventValueChanged];

    }

    #pragma mark -开关控制器

    -(void)swAction:(UISwitch*)sw{

    if(sw.on) {

    NSLog(@"开启");

    }else{

    NSLog(@"关闭");

    }

    }

    #pragma mark -页码控制器

    -(void)pageAction:(UIPageControl*)page{

    NSLog(@"%ld",page.currentPage);

    }

    #pragma mark -滑块控制器

    -(void)slideAction:(UISlider*)sl{

    NSLog(@"%f",sl.value);

    }

    #pragma mark =分段控制器

    -(void)segAction:(UISegmentedControl *)seg{

    获取视图对象的方式

    1.tag值

    2.属性

    if(seg.selectedSegmentIndex==0) {

    transition过渡动画

    参数1:开始视图

    参数2:结束视图

    //参数3:持续时间

    //参数4:动画选项

    //参数5:完成动画之后调用的block

    [UIViewtransitionFromView:self.greenViewtoView:self.redViewduration:1options:UIViewAnimationOptionTransitionCurlDowncompletion:^(BOOLfinished) {

    }];

    }

    if(seg.selectedSegmentIndex==1) {

    [UIViewtransitionFromView:self.redViewtoView:self.greenViewduration:1options:UIViewAnimationOptionTransitionCurlUpcompletion:^(BOOLfinished) {

    }];

    }

    NSLog(@"%ld",seg.selectedSegmentIndex);

    }

    - (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    Dispose of any resources that can be recreated.

    }

    相关文章

      网友评论

          本文标题:UIViewController

          本文链接:https://www.haomeiwen.com/subject/niupkttx.html