iPhone Segmented Control:UISegmentedControl Tutorial
来源:互联网 发布:js 对象类型 编辑:程序博客网 时间:2024/06/05 17:06
iPhone Segmented Control:UISegmentedControl Tutorial
A segmented control shows a horizontal list of items. Each segment looks like a button. The segments remains “pressed” even after the user lifts his finger.When a different segment is tapped, its corresponding value can be obtained.
Segmented control comes in handy when you want to show/hide different data without changing the current view.For e.g you can have a set of images and you display only one when a segment is selected. When you select a different segment, depending on that, the picture changes.
So lets get started.:
Step 1:Start Xcode and create a view based application with name “SegmentedControlDemo”.
Step 2:Open the “SegmentedControlDemoViewController.h” file and put the following code in it.
Here, we have declared a label and segmented control and set properties and outlets for both of them.
Step 3:Open the “SegmentedControlDemoViewController.m” file. Synthesize both the properties and release them.Also provide the implementation for segmentedControlIndexChanged method.
In the segmentedControlIndexChanged method, we have used a switch case which switches the selected segment index of the segmented control. For each case, we have set the text of the label to the respective segment selected.
Step 4: Save(command+s) the project.Now open the “SegmentedControlDemoViewController.xib” file from the Resources folder. Drag and drop a label and a segmented control from the library on the view as shown below. Stretch the edges of the label so that it becomes long enough to display “Segment x selected.”
Note: If you want more than two segments in the segmented control, go to Attributes Inspector for segmented control and change the value for Segments field.
Step 5:Select the File’s Owner in the xib window and open its Connections Inspector(command+2) and make the following connections.
Connect segmentControl to segmented control and segmentLabel to label. The Connections Inspector for File’s Owner will then look like this:
Step 6: Open the Connections Inspector for segmented control and link the value changed argument to the segmentedControlIndexChanged method in the File’s Owner.
Step 7: Build and run the project. You will see that when you tap different segments of the segmented control, the text of the label changes.
OUTPUT:
Thats all folks! You are now ready to meddle with segmented control.
- iPhone Segmented Control:UISegmentedControl Tutorial
- 自定义 Segmented Control
- 什么是segmented control
- segmented control的使用
- iPhone开发【十二】多视图技术总结之四:Segmented Control
- iPhone开发【十二】多视图技术总结之四:Segmented Control
- Segmented Control - 仿 app store的Segmented Control
- IOS学习之segmented control
- IOS学习之segmented control
- Scroll Segmented Control(Swift)
- How to use the Segmented Control
- 一个定制SEGMENTED CONTROL的开源代码
- iOS学习——Segmented Control
- iphone UISegmentedControl分段控件
- [IOS] iphone之UISegmentedControl
- iphone之UISegmentedControl
- iphone之UISegmentedControl
- iphone之UISegmentedControl
- c#操作word出现“rpc服务器不可用”
- 采撷
- 基于ARP欺骗的网络攻击程序源码
- c++写的MFC中截特定区域图像的程序
- VBScript 发送电子邮件
- iPhone Segmented Control:UISegmentedControl Tutorial
- 递增子序列数目计算的算法
- 【SVN】:Linux下使用SVN命令行(zz)
- Android中的状态机(续)
- Node.js 究竟是什么?
- Android 应用盈利模式的转变
- HTML4 和 HTML5 的10个关键区别
- 【LINUX】:Linux 用户(user)和用户组(group)管理概述
- c++画圆的程序