UISegmentedControl分段控件的基本概念和使用方法
2014-04-04 19:10
896 查看
转自:博客地址:http://blog.csdn.net/developer_jiangqq)
Author:hmjiangqq
Email:jiangqqlmj@163.com
UISegmentedControl
首先看下官网介绍:
A
a compact means to group together a number of controls.
A segmented control can display a title (an
or an image (
The
you add and remove segments, you can request that the action be animated with sliding and fading effects.
分段控件是一种选择控件,功能有点类似于Windows中的单选按钮,由两端或者更多段组成,
每个段相当于一个独立的按钮。这控件一般有两种样式-Plain&Bordered样式和Bar样式,
Bordered样式是在Plain样式上面加上了一个边框.Plain和Bordered样式中每一段都可以设置文本
和添加图片.Bar样式整体来说比较窄,在其中我们一般不会放置图片。
常用的属性和方法如下:
实例代码如下:
[objc] view
plaincopy
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
NSArray *array=@[@"搜索",@"选择",@"视频",@"图片"];
UISegmentedControl *segmentControl=[[UISegmentedControl alloc]initWithItems:array];
segmentControl.segmentedControlStyle=UISegmentedControlStyleBordered;
//设置位置 大小
segmentControl.frame=CGRectMake(60, 100, 200, 40);
//默认选择
segmentControl.selectedSegmentIndex=1;
//设置背景色
segmentControl.tintColor=[UIColor greenColor];
//设置监听事件
[segmentControl addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
[self.window addSubview:segmentControl];
[segmentControl release];
[self.window makeKeyAndVisible];
return YES;
}
-(void)change:(UISegmentedControl *)segmentControl{
NSLog(@"segmentControl %d",segmentControl.selectedSegmentIndex);
}
运行截图:
Author:hmjiangqq
Email:jiangqqlmj@163.com
UISegmentedControl
首先看下官网介绍:
A
UISegmentedControlobject is a horizontal control made of multiple segments, each segment functioning as a discrete button. A segmented control affords
a compact means to group together a number of controls.
A segmented control can display a title (an
NSStringobject)
or an image (
UIImageobject).
The
UISegmentedControlobject automatically resizes segments to fit proportionally within their superview unless they have a specific width set. When
you add and remove segments, you can request that the action be animated with sliding and fading effects.
分段控件是一种选择控件,功能有点类似于Windows中的单选按钮,由两端或者更多段组成,
每个段相当于一个独立的按钮。这控件一般有两种样式-Plain&Bordered样式和Bar样式,
Bordered样式是在Plain样式上面加上了一个边框.Plain和Bordered样式中每一段都可以设置文本
和添加图片.Bar样式整体来说比较窄,在其中我们一般不会放置图片。
常用的属性和方法如下:
实例代码如下:
[objc] view
plaincopy
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
NSArray *array=@[@"搜索",@"选择",@"视频",@"图片"];
UISegmentedControl *segmentControl=[[UISegmentedControl alloc]initWithItems:array];
segmentControl.segmentedControlStyle=UISegmentedControlStyleBordered;
//设置位置 大小
segmentControl.frame=CGRectMake(60, 100, 200, 40);
//默认选择
segmentControl.selectedSegmentIndex=1;
//设置背景色
segmentControl.tintColor=[UIColor greenColor];
//设置监听事件
[segmentControl addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
[self.window addSubview:segmentControl];
[segmentControl release];
[self.window makeKeyAndVisible];
return YES;
}
-(void)change:(UISegmentedControl *)segmentControl{
NSLog(@"segmentControl %d",segmentControl.selectedSegmentIndex);
}
运行截图:
相关文章推荐
- IOS学习笔记(七)之UISegmentedControl分段控件的基本概念和使用方法
- IOS学习笔记(七)之UISegmentedControl分段控件的基本概念和使用方法
- 【Objective-C】OC中自动释放池的基本概念和使用方法
- lucene.net的一些基本使用方法和概念
- 安卓控件使用系列14:ImageView的基本使用方法
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- CListCtrl控件的基本使用方法
- QTableView基本用法讲解,Qt表格控件的使用方法
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- Mysql存储过程------存储过程的基本概念和基本使用方法
- 基本控件的概念和使用
- Android中AlertDialog控件的基本使用和定制方法
- Java基本功练习十三(字符串和文本IO【相关概念、基本方法使用】)
- java多线程的基本概念与线程的使用方法
- Android中常用基本控件的使用方法和步骤(.txt)
- 【Objective-C】OC中KVO的基本概念和使用方法
- 【Objective-C】OC中KVO的基本概念和使用方法
- lucene.net的一些基本使用方法和概念
- lucene.net的一些基本使用方法和概念
- Android搜索控件的基本使用方法