UI1

it2024-11-07  2

// // ViewController.m // UI1_UISlider与UISegment // // Created by zhangxueming on 15/7/7. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 100, self.view.frame.size.width-100, 100)]; slider.backgroundColor = [UIColor cyanColor]; //设置value 最小值 (保证最大值大于最小值 滑块才能移动) slider.minimumValue = 100; //设置value 最大值 slider.maximumValue = 110; //设置最大值最小值一端的图片 slider.maximumValueImage = [UIImage imageNamed:@"truckmax"]; slider.minimumValueImage = [UIImage imageNamed:@"truckmin"]; //设置滑块的颜色 slider.thumbTintColor = [UIColor redColor]; //设置最小值轨道颜色 slider.minimumTrackTintColor = [UIColor blackColor]; //设置最大值轨道颜色 slider.maximumTrackTintColor = [UIColor greenColor]; //设置滑块的图片 [slider setThumbImage:[UIImage imageNamed:@"001.png"] forState:UIControlStateHighlighted]; [slider setMinimumTrackImage:[UIImage imageNamed:@"002.png"] forState:UIControlStateNormal]; [slider setMaximumTrackImage:[UIImage imageNamed:@"005.png"] forState:UIControlStateNormal]; [slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:slider]; //分段选取器 NSArray *titles = @[@"百度",@"音乐",@"贴吧",@"图片"]; UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:titles]; segment.frame = CGRectMake(10, 300, self.view.frame.size.width-20, 50); segment.selectedSegmentIndex = 1; [segment addTarget:self action:@selector(segmentSelectedValueChange:) forControlEvents:UIControlEventValueChanged]; //增加分段 [segment insertSegmentWithTitle:@"地图" atIndex:1 animated:YES]; [self.view addSubview:segment]; } - (void)sliderValueChange:(UISlider *)slider { //默认value值0.0~1.0 NSLog(@"value = %.2f", slider.value); } - (void)segmentSelectedValueChange:(UISegmentedControl *)segment { NSLog(@"selectedValue = %li", segment.selectedSegmentIndex); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

 

转载于:https://www.cnblogs.com/0515offer/p/4638764.html

相关资源:数据结构—成绩单生成器
最新回复(0)