ui控件

来源:互联网 发布:淘宝评价没有图片上传 编辑:程序博客网 时间:2024/05/17 00:55

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


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

//    进度条

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

    slider.minimumValue =0//最小值

    slider.maximumValue =5.0f//最大值

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

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

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

    [self.viewaddSubview:slider];

    [sliderrelease];

    

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

 


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

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

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

    [imageVstartAnimating];    //开始播放

}


//    分段控制器

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

    

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

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

    segmented.backgroundColor = [UIColoryellowColor];

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

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

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

    [self.viewaddSubview:segmented];

    [segmentedrelease];

    

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

  


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

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

    

}

//    UISwitch 开关

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

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

    sw.thumbTintColor = [UIColorgrayColor];

    sw.tintColor = [UIColorpurpleColor];

    sw.onTintColor = [UIColorblueColor];

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

    [self.viewaddSubview:sw];

    [swrelease];

      

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

    //    switch 只有两种状态

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

}


//    - / +

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

    step.backgroundColor = [UIColorpurpleColor];

    [self.viewaddSubview:step];

    [steprelease];


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

    

    step.value =100;  

    step.maximumValue =200;

    step.minimumValue =0;

//    默认增加值为 1

    step.stepValue =5;

    

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


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

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

}






1 0
原创粉丝点击