前言:我是在完成截图后,希望弹出类似QQ那样的选择按钮,比如:保存、取消、完成。然后用到了这个控件。这个控件的用法相当的简单,没有什么好讲的。
唯有一点,需要特别注意,那就是对这个控件的点击响应。当点击这种类似button的控件时,我们首先想到的响应事件肯定是UIControlEventTouchUpInside ,但是这个segmentedControl不是,它响应的竟然是UIControlEventValueChanged这个事件。当然,对于这种分不清响应事件是哪个的,我们可以直接把响应事件设为UIControlEventAllEvents。
但既然写到这个控件了,我就还是把它的常用方法列出来吧!
先上代码:
//用户选择框 NSArray *segArray = [[NSArray arrayWithObjects:@"保存", @"取消",@"完成",nil]retain]; _segControl = [[UISegmentedControl alloc]initWithItems:segArray]; [_segControl addTarget:self action:@selector(segControlResponse:) forControlEvents:UIControlEventAllEvents]; [segArray release];
一、介绍
分段控件UISegemetedControl提供一栏按钮(有时称为按钮栏),但只能激活其中一个按钮。分段控件会导致用户在屏幕上看到的内容发生变化。它们常用于在不同类别的信息之间选择,或在不同的应用屏幕之间切换。
二、样式
它有四种基本样式,分别是:
typedef NS_ENUM(NSInteger, UISegmentedControlStyle) { UISegmentedControlStylePlain, // large plain UISegmentedControlStyleBordered, // large bordered UISegmentedControlStyleBar, // small button/nav bar style. tintable UISegmentedControlStyleBezeled, // DEPRECATED. Do not use this style. };
对应的图像是
三、其他选项
请参考:http://www.cnblogs.com/top5/archive/2012/05/17/2506618.html这篇博客对这个控件有详细的介绍。