iosui学习中的课堂笔记 UISegmentedControl。UISlider。UIStepper。UISwitch。

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 1.分段控件(UISegmentedControl)
    
    UISegmentedControl *segmented = [[UISegmentedControl alloc]initWithItems:@[@"伊泽瑞尔", @"德邦总管", @"嘉文四世"]];
    //给segmentedControl绑定方法
    [segmented addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
    //改变segmented的颜色
    [segmented setTintColor:[UIColor grayColor]];
    [self.view addSubview:segmented];
    //滑动控件
    UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(20, 470, 260, 40)];
    [self.view addSubview:slider];
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider release];
    
    //设置silder 的最大值/最小值
    
    [slider setMaximumValue:100];
    [slider setMinimumValue:0];
    //利用UIImageView播放Gif图片
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 200, 200, 200)];
   // [imageView setBackgroundColor:[UIColor yellowColor]];
    [self.view addSubview:imageView];
    [imageView release];
    //产生一组图片
    NSMutableArray *imageArray = [NSMutableArray array];
    for (int i = 0; i < 22; i++) {
        //按顺序产生数组
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Zombie%d.tiff", i + 1]];
        //把图片添加到数组中
        [imageArray addObject:image];
    }
    //将图片数组给imageView等待播放
    imageView.animationImages = imageArray;
    //播放速度
    imageView.animationDuration = 0.00001;//播放一遍所需要的时间
     //播放次数
    imageView.animationRepeatCount = 0;
    //播放
    [imageView startAnimating];
    //播放次数
    UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(220, 220, 120, 40)];
    [stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:stepper];
    [stepper setMaximumValue:100];
    [stepper setMinimumValue:0];
    [stepper release];
    
    UISwitch *swich = [[UISwitch alloc]initWithFrame:CGRectMake(20, 220, 120, 40)];
    [swich addTarget:self action:@selector(swichAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:swich];
    [swich release];
    
    //设置背景图片
    //[segmented setBackgroundImage:[UIImage imageNamed:@"伊泽.jpg"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    segmented.frame = CGRectMake(20, 40, 280, 40);
    [segmented release];
}
- (void)swichAction:(UISwitch *)swich
{
    NSLog(@"关/开");

}
- (void)stepperAction:(UIStepper *)stepper
{
    NSLog(@"增/减");
    NSLog(@"增/减%f", stepper.value);
}
- (void)sliderAction:(UISlider *)slider
{
    //slider.value  当前滑动到得值
    NSLog(@"滑动%f", slider.value);
    NSLog(@"滑动");
}
- (void)segmentedAction:(UISegmentedControl *)seg
{
    //通过点击下标判断
    if (seg.selectedSegmentIndex == 0) {
        NSLog(@"是时候表演真正的技术了");
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://15542470822"]];//打电话 发短信 打开网页 发邮件等
        
    }
    if (seg.selectedSegmentIndex == 1) {
        NSLog(@"这就是我德邦总管赵兴");
    }
    if (seg.selectedSegmentIndex == 2)
        NSLog(@"德玛西亚");
    //插入一个分段
   // [seg insertSegmentWithTitle:@"皮城女警" atIndex:0 animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值