ui控件

  苹果的来袭, 正在改变着我们的生活,最近发现,周围想学 IOS 开发的人渐渐多了起来, 于是,总结了些UI控件的一些基本东西,UIslider, UISementedControl, Switch, UIStepper的基本应用,希望对他们能够帮助.


声明 在 MRC 在手动控制内存机制下进行

//    进度条

    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 600, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];

    slider.minimumValue = 0//最小值

    slider.maximumValue = 5.0f//最大值

    slider.minimumTrackTintColor = [UIColor yellowColor];  //进行过的进度条颜色

    slider.maximumTrackTintColor = [UIColor greenColor];   //未进行过的进度条颜色

    slider.thumbTintColor = [UIColor redColor];  //控制按钮的颜色

    [self.view addSubview:slider];

    [slider release];

    

    [slider addTarget:self action:@selector(slider:) forControlEvents:UIControlEventValueChanged];  //target action 方法

 


- (void)slider:(UISlider *)sli {

    UIImageView *imageV = (UIImageView *)[self.view viewWithTag:1000];

    [imageV setAnimationDuration:sli.value];  //根据value读取进度

    [imageV startAnimating];    //开始播放

}


//    分段控制器

    NSArray *str = [NSArray arrayWithObjects:@"1",@"2",@"3", nil];

    

    UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:str];

    segmented.frame = CGRectMake(30, 50, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    segmented.backgroundColor = [UIColor yellowColor];

    segmented.selectedSegmentIndex = 0;   //设置当前所选择的分段

    segmented.tintColor = [UIColor blackColor];   //设置主色调

    [segmented setImage:[UIImage imageNamed:@"2.png"] forSegmentAtIndex:2]; //在指定位置插入图片

    [self.view addSubview:segmented];

    [segmented release];

    

    [segmented addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];  //添加事件

  


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

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

    

}

//    UISwitch 开关

    UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(0, 350, 375, 667)];

    sw.backgroundColor = [UIColor redColor];    //设置背景颜色

    sw.thumbTintColor = [UIColor grayColor];

    sw.tintColor = [UIColor purpleColor];

    sw.onTintColor = [UIColor blueColor];

    [sw addTarget:self action:@selector(switchActin:) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:sw];

    [sw release];

      

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

    //    switch 只有两种状态

    NSLog(@"%d", sw.isOn);

}


//    - / +

    UIStepper *step = [[UIStepper alloc] initWithFrame:CGRectMake(0, 500, 100, 20)];

    step.backgroundColor = [UIColor purpleColor];

    [self.view addSubview:step];

    [step release];


//    默认最小值为0, 最大值为 100

    

    step.value = 100;  

    step.maximumValue = 200;

    step.minimumValue = 0;

//    默认增加值为 1

    step.stepValue = 5;

    

    [step addTarget:self action:@selector(stepper:) forControlEvents:UIControlEventValueChanged];


- (void)stepper:(UIStepper *)step {

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

}






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值