UISegmentControl,UISwich,UIPageControl

  1 #import "ViewController.h"
  2
  3 @interface ViewController ()
  4 @property (strong,nonatomic) UIView *red;
  5 @property (strong,nonatomic) UIView *blue;
  6 @property (strong,nonatomic) UIView *yellow;
  7 @end
  8
  9 @implementation ViewController
 10
 11
 12 - (void)viewDidLoad {
 13     [super viewDidLoad];
 14     // Do any additional setup after loading the view, typically from a nib.
 15     //登录页面
 16     self.red = [[UIView alloc] initWithFrame:self.view.frame];
 17     self.red.backgroundColor = [UIColor redColor];
 18     [self.view addSubview:self.red];
 19     UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 50)];
 20     lable.text = @"登录页面";
 21     lable.font = [UIFont systemFontOfSize:40];
 22     [self.red addSubview:lable];
 23
 24     //注册页面
 25     self.blue = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 414, 736)];
 26     self.blue.backgroundColor = [UIColor blueColor];
 27     [self.view addSubview:self.blue];
 28     UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 50)];
 29     lable1.text = @"注册页面";
 30     lable1.font = [UIFont systemFontOfSize:40];
 31     [self.blue addSubview:lable1];
 32
 33
 34     //忘记密码页面
 35     self.yellow = [[UIView alloc] initWithFrame:self.view.frame];
 36     self.yellow.backgroundColor = [UIColor yellowColor];
 37     [self.view addSubview:self.yellow];
 38     UILabel *lable2 = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 50)];
 39     lable2.text = @"忘记密码";
 40     lable2.font = [UIFont systemFontOfSize:40];
 41     [self.yellow addSubview:lable2];
 42
 43 #pragma mark------UISegmentControl----------
 44     //创建分段控件
 45     UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:@[@"登录",@"注册",@"忘记密码"]];
 46     segmented.frame = CGRectMake(0, 60, self.view.frame.size.width, 80);
 47        //设置默认选中值
 48     segmented.selectedSegmentIndex = 0;
 49
 50     //为指定的下标分段设置标题
 51     [segmented setTitle:@"抗日胜利" forSegmentAtIndex:1];
 52
 53     //添加点击事件
 54     [segmented addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
 55
 56     segmented.tag = 999;
 57
 58     //添加到视图
 59     [self.view addSubview:segmented];
 60
 61 #pragma mark---------UIPageControl-----------
 62     //创建滑块
 63     UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(100, self.view.frame.size.height - 100, 300, 40)];
 64     //设置pageController的页数
 65     pageControl.numberOfPages = 4;
 66     //设置当前页(默认为0)
 67     pageControl.currentPage = 1;
 68     //设置颜色
 69     pageControl.backgroundColor = [UIColor blackColor];
 70     //添加事件
 71     [pageControl addTarget:self action:@selector(pangeControlAction:) forControlEvents:UIControlEventValueChanged];
 72     [self.view addSubview:pageControl];
 73     //循环创建4个图片
 74     for (int i = 0; i < 4; i++) {
 75         UIImageView *picture = [[UIImageView alloc] initWithFrame:self.view.frame];
 76         [picture setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]]];
 77         picture.tag = 1000 + i;
 78         [self.view addSubview:picture];
 79     }
 80     pageControl.tag  =1111;
 81     [self.view bringSubviewToFront:pageControl];
 82
 83 #pragma mark-------UISwitch
 84     //创建一个UISwitch  注意:这里的frame只有origin起作用,size使用系统默认大小
 85     UISwitch *firstSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 170, 0, 0)];
 86
 87     //设置开关开启时候的颜色
 88     firstSwitch.onTintColor = [UIColor greenColor];
 89
 90     //设置开关风格颜色
 91     firstSwitch.tintColor = [UIColor orangeColor];
 92
 93     //设置开关按钮颜色
 94     firstSwitch.thumbTintColor = [UIColor redColor];
 95
 96     //设置开关状态
 97
 98     firstSwitch.on = YES;
 99     [firstSwitch addTarget:self action:@selector(action2:) forControlEvents:UIControlEventValueChanged];
100
101     [self.view addSubview:firstSwitch];
102     [self.view bringSubviewToFront:firstSwitch];
103
104
105
106 }
107 //switch事件
108 -(void)action2:(UISwitch *)first
109 {
110     UIPageControl *page = (UIPageControl *)[self.view viewWithTag:1111];
111     if (first.on == NO) {
112         page.userInteractionEnabled = NO;
113     }else
114     {
115         page.userInteractionEnabled = YES;
116     }
117 }
118 //pageControl事件
119 -(void)pangeControlAction:(UIPageControl *)pageControl
120 {
121     [self.view bringSubviewToFront:[self.view viewWithTag:pageControl.currentPage + 1000]];
122     [self.view bringSubviewToFront:pageControl];
123
124    // UISegmentedControl *segment = (UISegmentedControl *)[self.view viewWithTag:999];
125     //[self.view bringSubviewToFront:segment];
126
127
128    }
129
130
131 //segmengted事件
132 -(void)segmentedAction:(UISegmentedControl *)segment
133 {
134     switch (segment.selectedSegmentIndex) {
135         case 0:
136             [self.view insertSubview:self.red belowSubview:segment];
137             break;
138         case 1:
139             [self.view insertSubview:self.blue belowSubview:segment];
140             break;
141         case 2:
142             [self.view insertSubview:self.yellow belowSubview:segment];
143             break;
144
145         default:
146             break;
147     }
148 }
149
150 - (void)didReceiveMemoryWarning {
151     [super didReceiveMemoryWarning];
152     // Dispose of any resources that can be recreated.
153 }
154
155 @end
时间: 2024-11-08 20:19:05

UISegmentControl,UISwich,UIPageControl的相关文章

iOS中UIButton控件的用法及部分参数解释

在UI控件中UIButton是极其常用的一类控件,它的类对象创建与大多数UI控件使用实例方法init创建不同,通常使用类方法创建: + (id)buttonWithType:(UIButtonType)buttonType; 如果使用实例方法创建UIButton对象,如: UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 50)]; 对象的创建是没有任何问题的,但是当为这个button对象设置一

iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

首先创建一个引导图的控制器类 UserGuideViewController.h和UserGuideViewController.m #import <UIKit/UIKit.h> #import "firstViewController.h" #define WIDTH self.view.frame.size.width #define HEIGHT self.view.frame.size.height @interface UserGuideViewControll

IOS-OC-基本控件之UIPageControl

UIPageControl(页面控制器,就是桌面的那些小点点,每个点代表一个界面) 父类是 UIControl. IOS开发中常用的基本控件,主要和UIScrollView一起使用,比较常用的就是有些APP主页面会有一些图片自动转换,也可以用而人为的转换,本文主要是列出常用的属性及方法(注XCode版本为7.2) 属性如下: @property(nonatomic) NSInteger numberOfPages;          //总页数,默认0页 @property(nonatomic)

UISegmentControl 、UIStepper

UISegmentControl .UIStepper UISegmentControl 1. UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:@[@"1",@"2",@"3",@"4"]];2.segmentControl.frame = (CGRect){50,100,100,50}; 等同于 1. UISegme

scrollView实现基础中心点缩放及与UIPageControl结合使用

一般来说scrollView与UIPageControl都是结合使用,因为在使用滚动视图的时候 ,使用UIPageControl,用户可以 清楚 的明白显示的内容有多少页,如果 没有的话,总不能让用户一个个的去数.用户体验效果不理想. 一般来说,在滑动scrollView的时候,UIPageControl的选中点的位置也会有相应的变化.当然,反之来说,改变选中点的位置,相应的scrollView显示的内容也会产生变化 . 因为我这边需要实现的效果是:最后一张向后滑动之后,会自动跳到第一张显示的内

UIPageControl

UIPageControl用于显示滑动视图实际拥有的页数 UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, 100, 100, 30); page.background = [UIColor redColor]; page.numberOfPages = 5;  //设置拥有的页数 page.currentPage = 2; //设置当前显示第几个点 page.pageIndicatorTintC

通过UIScrollView和UIPageControl结合制作相册

1.创建UIScrollView视图: UIScrollView *aScrollView = [[[UIScrollView alloc] initWithFrame:self.view.bounds] autorelease]; aScrollView.backgroundColor = [UIColor redColor]; [self.view addSubview:aScrollView]; aScrollView.contentSize = CGSizeMake(CGRectGetW

UI第六讲.UISegmentControl的使用,UISliser的使用,UIImageView的使用,UIControl的作用

一.UISegmentedControl的使用(分段控件) UISegmentedControl是iOS中的分段控件. 每个segment都能被点击,相当于集成了若干个button.通常我们会点击不同的segment来切换不同的view. 示例图: 常用方法: 示例代码: 基本的UISegmentControl的用法,同时通过其addtarget/action方法实点击切换view背景色的效果 效果图:点击UISegmentControl的item,切换背景色 二.UISlider的使用(滑块控

UIPageControl 与 UIScrollView

#import "MainViewController.h" #define WIDTH self.view.frame.size.width #define HEIGHT self.view.frame.size.height @interface MainViewController ()<UIScrollViewDelegate> @property(nonatomic, retain)UIScrollView *scrollView; @end @implement