UISegmentedControl 使用
2016-02-23 07:13
489 查看
//屏幕尺寸 #define kScreenWidth [UIScreen mainScreen].bounds.size.width #define kScreenHeight [UIScreen mainScreen].bounds.size.height //占屏幕百分比 #define RectWithWidth(w) kScreenWidth * w #define RectWithHeight(h) kScreenHeight * h //传入x,y,w,h所占屏幕宽高的百分比得到控件frame #define RectMakeWithPercent(xPercent,yPercent,wPercent,hPercent) CGRectMake(RectWithWidth(xPercent), RectWithHeight(yPercent), RectWithWidth(wPercent), RectWithHeight(hPercent))
-(void)creatSegmentedControl{ //初始化 UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:@[@"车次查询",@"站站查询"]]; //尺寸 (简单屏幕适配) [segmentedController setFrame:RectMakeWithPercent(20/375.0, 84/667.0, 335/375.0, 44.0/667)]; //默认选择索引 [segmentedController setSelectedSegmentIndex:0]; //设置选中颜色 [segmentedController setTintColor:colorWithRGBA(93, 151, 223, 1)]; //点击后是否恢复原样 [segmentedController setMomentary:NO]; //设置指定索引的题目 (在初始化中已经设置,一般不用) //[segmentedController setTitle:@"站站查询" forSegmentAtIndex:1]; [segmentedController addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged]; //加载到视图 [self.view addSubview:segmentedController]; } -(void)segmentedAction:(UISegmentedControl *)segmentedController{ if ([segmentedController selectedSegmentIndex] == 0) { NSLog(@"车次查询->相应UI布局"); // [self layoutUIByStationCode]; }else{ NSLog(@"站站查询->相应UI布局"); // [self layoutUIByStationToStation]; } }
相关文章推荐
- [Protractor] Locators and Suites in Protractor
- Android-节日短信送祝福(UI篇:3-选择联系人、发送短信、显示历史记录)
- impala+hue
- Codeforces 620D Lipshitz Sequence RMQ+二分
- Divide and Conquer
- UI视图交互与事件机制
- UINT8_T / UINT16_T / UINT32_T /UINT64_T 是什么数据类型(转)
- JSP内置对象——request内置对象(1)
- JSP内置对象——request内置对象(2)
- 关于决解EasyUI中Tabs标签页下使用百度地图API异常
- jsp继续学习(request对象)
- Theano-Deep Learning Tutorials 笔记:Modeling and generating sequences of polyphonic music with the RNN
- iOS(学习4) UIWindow 和 UIView
- Android UI效果之绘图篇(三)
- Solving “Dynamic Web Module 3.0 requires Java 1.6 or newer” in Maven Projects
- iOS 弹窗UIAlertView、UIActionSheet、UIAlertController简述 —— HERO博客
- 解析UITableViewCell的重用
- 有关error:invalid type arguement of unary'*'(hava 'int')
- Intel处理器CPUID指令学习
- iOS7.0后隐藏状态栏(UIStatusBar)