UISegmentedControl(转)
初始化UISegmentedControl
NSArray *arr = [[NSArray alloc]initWithObjects:@"轻拍",@"长按",@"清扫",@"旋转",@"捏合",@"拖拽", nil];
//先创建一个数组用于设置标题
UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:arr];
//在没有设置[segment setApportionsSegmentWidthsByContent:YES]时,每个的宽度按segment的宽度平分
segment.frame = CGRectMake(0, 400, 320, 40);
//设置frame
管理Segment的内容
[segment setTitle:@"大便" forSegmentAtIndex:3];
//设置下标为3的segment的标题 下标以0开始 IOS里的所有下标都是以0开始
[segment setImage:[UIImage imageNamed:@"3"] forSegmentAtIndex:4];
//设置下标为4的segment的图片
管理Segments
[segment insertSegmentWithImage:[UIImage imageNamed:@"3"] atIndex:2 animated:YES]; //设置图片
[segment insertSegmentWithTitle:@"ddd" atIndex:0 animated:YES];//设置标题
[segment numberOfSegments];//得到segment的数量
[segment removeAllSegments];//移出所有segment
[segment removeSegmentAtIndex:2 animated:YES];//移出下标为2的segment
segment.selectedSegmentIndex = 0;//选中第几个segment 一般用于初始化时选中
管理Segment的行为和外观
segment.momentary = NO;
//默认为NO 当设置为YES时,当被选中后,一会儿后不显示被选中状态(最左边的样子),不选中状态即下图的右边几个按钮一样
segment.segmentedControlStyle = UISegmentedControlStyleBar;
typedef enum {
UISegmentedControlStylePlain,
UISegmentedControlStyleBordered,
UISegmentedControlStyleBar,
UISegmentedControlStyleBezeled,
} UISegmentedControlStyle;
//设置样式 当为Bordered和Bar时tintColor才有效 下图为tintcolor为红色时的样子
//Bar样式
//Bordered
[segment setEnabled:NO]; //设置segment是否可用 此方法是其父类UIControl的方法
[segment setEnabled:NO forSegmentAtIndex:2];//设置下标为2的segment不可用
[segment setWidth:100 forSegmentAtIndex:2]; //这时下表为2的segment的宽度
[segment setContentOffset:CGSizeMake(10, 10) forSegmentAtIndex:2];//设置内容偏移
segment.apportionsSegmentWidthsByContent = YES; //是否根据segment的内容改变segment的宽度
自定义外观
[segment setTintColor:[UIColor redColor]]; //设置segments的颜色
[segment setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
typedef enum {
UIBarMetricsDefault, //竖屏
UIBarMetricsLandscapePhone, 横屏
} UIBarMetrics;
//设置在某个状态下segments的背景图片
[segment setTitleTextAttributes:dic forState:UIControlStateNormal];
NSString *const UITextAttributeFont; value: UIFont
NSString *const UITextAttributeTextColor; value: UIColor
NSString *const UITextAttributeTextShadowColor; value: UIColor
NSString *const UITextAttributeTextShadowOffset; value: NSValue wrapping a UIOffset
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],UITextAttributeTextColor,[UIFont fontWithName:@"SnellRoundhand-Bold" size:24],UITextAttributeFont ,nil];
//设置标题的颜色 字体和大小 阴影和阴影颜色
[segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
//当选中不同的segment时,会执行change:方法
UISegmentedControl(转)的更多相关文章
- iOS在导航栏上居中显示分段控件(UISegmentedControl)
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil]; segmentedCont ...
- 【UISegmentedControl】- 分段控件
一.初始化 二.常见的属性 1.segmentedControlStyle属性:设置基本的样式 2.momentary属性:设置在点击后是否恢复原样 . 3.numberOfSegments属性:只读 ...
- UI控件(UISegmentedControl)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSArray* segmentArray = [[ ...
- UI第八节——UISegmentedControl
- (void)viewDidLoad { [super viewDidLoad]; NSArray *items = @[@"消息", @"电话" ...
- UISegmentedControl 的使用
/** 设置选择器 */ - (void)setUpSegmentCtr { UISegmentedControl *segmentCtr = [[UISegmentedControl alloc] ...
- UISegmentedControl和UIStepper的使用
UISegmentedControl:分栏控件,常用的属性和方法是 1.tintColor:控制分栏控件的颜色风格 2.insertSegmentWithTitle(Image):插入分栏标题(图片) ...
- UISegmentedControl 控件
一.创建 UISegmentedControl* mySegmentedControl = [[UISegmentedControl alloc]initWithItems:nil]; 是不是很奇怪没 ...
- UI中一些不常用的控件UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController
//UIActivityIndicatorView //小菊花,加载 #import "ActivityIndicatorVC.h" @interface ActivityIndi ...
- UISegmentedControl(人物简介)
效果图 当你点击上面人物名字的时候 ,就可以随意切换人物. 这个很有趣 , 你还可以试着添加音乐播放器 .以及一些别的来完善你想做的. 好吧 , 废话不多说 , 上代码. #import " ...
- UILabel UISwitch UISegmentedControl UIAlertView
基础小控件 /***************************************UIlabel*************************************/ UILabel ...
随机推荐
- android studio 0.8.11 如何导入Library(新手向)
网上下了个ViewPagerIndicator的库,下载下来是个zip包,解压开来,里面有一个library和一个sample文件夹,还有一些其他的配置文件. 其中library就是我们新项目中要引入 ...
- iOS初级数据持久化 沙盒机制 归档与反归档
数据持久化就是数据保存成文件,存储到程序中的沙盒中. 沙盒构成 Document 存储用户数据,需要备份的信息 Caches 缓存文件, 程序专用的支持文件 Temp 临时文件 通过代码查找程序沙盒的 ...
- TCP定时器
http://network.51cto.com/art/201412/459352.htm TCP 是提供可靠的传输层,它使用的方法之一就是确认从另一端收到的数据.但是数据和确认都可能会丢失.TCP ...
- dede让channelartlist标签支持currentstyle属性 完美解决
打开include\taglib\channelartlist.lib.php 找到 $pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]); ...
- JavaScript:window窗口对象
在JavaScript中,window表示的就是一个窗口对象.所以在整个处理过程之中,所有的操作都是以弹框为主 的.范例1:使用警告框 <script type="text/javas ...
- SqlServer基础:IsNull
SELECT @temp = ISNULL(point, 0) FROM dbo.User where Nid=6 如果User表中的point字段为null的话,则对@temp赋值0
- Tomcat Context配置(转)
<Context>元素的属性:path:指定访问该Web应用的URL入口.docBase:指定Web应用的文件路径,可以给定绝对路径,也可以给定相对于<Host>的appBas ...
- oracle ORA-00001:违反唯一约束条件
--获取约束信息 select * from information_schema.constraint_column_usage---可以获取指定数据库中的所有约束的信息以及约束与列的对应关系 go ...
- C# 英式日期插入Access数据库错误问题
插入数据库语句如下 string insertSql = string.Format("insert into info(MeasureIDID,Val,UpdateTime) select ...
- javascript 正则表达式基础知识汇总
正则表达式:对字符串中的信息实现查找.替换和提取操作.(不支持注释和空白,必须写在一行内)正则表达式的创建:包含在一对斜杠之间的字符(直接量语法)例如:var pattern = /s$/; ...