1.UISegmentedControl
①:初始
self.segment = [[UISegmentedControl alloc]initWithItems:
[NSArray arrayWithObjects:@"一卡通",@"信用卡",@"一网通", nil]];
self.segment.frame = CGRectMake(0, 20, self.frame.size.width, 50);
[self addSubview:_segment];
②:设置标题
[self.rv.segment setTitle:@"第二项" forSegmentAtIndex:0];
③:默认被选中的选项
self.rv.segment.selectedSegmentIndex = 1;
④:边框和字体的颜色
self.rv.segment.tintColor = [UIColor orangeColor];
⑤:设置图片
self.rv.segment setImage:(UIImage *) forSegmentAtIndex:<#(NSUInteger)#>
⑥:获取图片
self.rv.segment imageForSegmentAtIndex:
⑦:获取title
self.rv.segment titleForSegmentAtIndex:<#(NSUInteger)#>
⑧:插入一个
[self.rv.segment insertSegmentWithTitle:@"3" atIndex:3 animated:YES];
⑨:删除一个
[self.rv.segment removeSegmentAtIndex:3 animated:YES];
⑩:事件
[self.rv.segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
- (void)segmentAction:(UISegmentedControl *)sender{
if (sender.selectedSegmentIndex == 0) {
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, self.rv.frame.size.width, self.rv.frame.size.height - 70)];
view1.backgroundColor = [UIColor colorWithRed:arc4random()%2/1.0 green:arc4random()%2/1.0 blue:arc4random()%2/1.0 alpha:1];
[self.rv addSubview:view1];
}else if (sender.selectedSegmentIndex == 1){
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, 375, 600)];
view2.backgroundColor = [UIColor colorWithRed:arc4random()%2/1.0 green:arc4random()%2/1.0 blue:arc4random()%2/1.0 alpha:1];
[self.rv addSubview:view2];
}else if (sender.selectedSegmentIndex == 2){
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, 375, 600)];
view3.backgroundColor = [UIColor colorWithRed:arc4random()%2/1.0 green:arc4random()%2/1.0 blue:arc4random()%2/1.0 alpha:1];
[self.rv addSubview:view3];}}
2.UISlider
①:初始
self.slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 100, 280, 50)];
②:设置最大值
self.slider.minimumValue = 0;
③:设置最小值
self.slider.maximumValue = 1;
④:设置最大值的滑条颜色
self.slider.maximumTrackTintColor = [UIColor blackColor];
⑤:设置最小值的滑条颜色
self.slider.minimumTrackTintColor = [UIColor greenColor];
⑥:右边加图片
self.slider.maximumValueImage = [UIImage imageNamed:@"1.png"];
⑦:左边加图片
self.slider.minimumValueImage = [UIImage imageNamed:@"2.png"];
⑧:圆点颜色
self.slider.thumbTintColor = [UIColor redColor];
⑨:设置圆点图片
self.slider setThumbImage:<#(UIImage *)#> forState:<#(UIControlState)#>
⑩:事件
[self.rv.slider addTarget:self action:@selector(sliderAction:)
forControlEvents:UIControlEventValueChanged];
// 注意:UIControlEventValueChanged的方法
- (void)sliderAction:(UISlider *)sender{
NSLog(@"%f",sender.value);// 获取当前滑条所在的值
self.rv.alpha = sender.value;// 透明度控制}
3.UIImageView
动画:
- (void)viewDidLoad {
// 父类视图加载完成
[super viewDidLoad];
// 做动态图的方法
[self MoveImageArr];}
- (void)MoveImageArr{
NSMutableArray *imageArr = [NSMutableArray array];
for (int i = 0; i < 7; i++)
{ NSString *nameStr = [NSString stringWithFormat:@"%d.tiff",i];
[imageArr addObject:[UIImage imageNamed:nameStr]];}
self.rv.mv.animationImages = imageArr;
// 时间间隔
self.rv.mv.animationDuration = 0.1;
// 重复次数
// self.rv.mv.animationRepeatCount = 3;
// 开始动画
[self.rv.mv.mvstartAnimating];
// 结束动画
// [self.rv.mv. stopAnimating];}
4.UIControl
UIControl 所有控制类的控件直接继承于UIControl
// 核心方法 add target action
// 为控制控件通过 addTarget: action: forControlEvents: 方法来添加事件。
// 通过 removeTarget: action: forControlEvents: 来移除事件。
5.已学类的继承