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 ...
随机推荐
- LogBack配置详解(一)
一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文 ...
- java时间戳转date(转)
1.时间戳的定义 时间戳(timestamp),通常是一个数字序列,唯一地标识某一刻的时间,指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起 ...
- iOS基础
1.属性readwrite,readonly,assign,retain,copy,nonatomic 各是什么作用,在那种情况下用? readwrite 是可读可写特性:需要生成getter方法和s ...
- Metro之Popup控件的使用(登录)
最终实现效果如下: 添加用户控件LoginPage.xaml,前台代码 <Popup x:Name="LoginPopup" Width="{Binding Ele ...
- Java遇见HTML——JSP篇之JavaBeans
一.JavaBean简介及设计原则 设计原则:公有类.无参的公有构造方法.属性私有.有getter and setter方法 实例: 二.Jsp动作元素 JSP动作标签分为五大类: 三.在JSP页面中 ...
- Windows 7 / Windows 10 安装 IPX/SPX
以我的系统为例: Windows 7/10 x64 首先下载 NWLINK IPX/SPX 驱动(这是 Microsoft 对 IPX/SPX 的实现.) http://pan.baidu.com/s ...
- PLSQL 申明和游标
--从键盘输入一个数 accept b prompt '请输入一个大于零的数字'; declare anum number := &b; begin loop dbms_output.put_ ...
- pptp建立vpn
1. 安装依赖 ppp yum -y install ppp 2. 编译安装pptpd wget http://jaist.dl.sourceforge.net/project/poptop/pptp ...
- Linux启动时卡住
该系统本是oracle rac的测试环境,在删除oracle软件后重启时系统卡住(没有按照oracle官方要求删除oracle软件).如下图: 处理过程: 1.使用单用户模式登陆 先在GRUB启动菜单 ...
- Xcode 遇到 App Transport Security has blocked a cleartext HTTP 错误
今天用Xcode 创建新项目用到 URL 发送请求时,报下面的错: “App Transport Security has blocked a cleartext HTTP (http://) re ...