博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UISegmentedControl的所有操作总结
阅读量:6326 次
发布时间:2019-06-22

本文共 4971 字,大约阅读时间需要 16 分钟。

#import "SegmentedControlTestViewController.h"  @implementation SegmentedControlTestViewController  @synthesize segmentedControl;  /****************************************      Tasks     Initializing a Segmented Control      – initWithItems:       Managing Segment Content      – setImage:forSegmentAtIndex:        – imageForSegmentAtIndex:        – setTitle:forSegmentAtIndex:        – titleForSegmentAtIndex:       Managing Segments      – insertSegmentWithImage:atIndex:animated:        – insertSegmentWithTitle:atIndex:animated:        numberOfSegments  property        – removeAllSegments        – removeSegmentAtIndex:animated:        selectedSegmentIndex  property       Managing Segment Behavior and Appearance      momentary  property        segmentedControlStyle  property        tintColor  property        – setEnabled:forSegmentAtIndex:        – isEnabledForSegmentAtIndex:        – setContentOffset:forSegmentAtIndex:        – contentOffsetForSegmentAtIndex:        – setWidth:forSegmentAtIndex:        – widthForSegmentAtIndex:       *********************************************/  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.      - (void)viewDidLoad {          NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",nil];  //初始化UISegmentedControl          UISegmentedControl *segmentedTemp = [[UISegmentedControl alloc]initWithItems:segmentedArray];          segmentedControl = segmentedTemp;          segmentedControl.frame = CGRectMake(60.0, 10.0, 200.0, 50.0);          [segmentedControl setTitle:@"two" forSegmentAtIndex:1];//设置指定索引的题目          [segmentedControl setImage:[UIImage imageNamed:@"lan.png"] forSegmentAtIndex:3];//设置指定索引的图片          [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"mei.png"] atIndex:2 animated:NO];//在指定索引插入一个选项并设置图片          [segmentedControl insertSegmentWithTitle:@"insert" atIndex:3 animated:NO];//在指定索引插入一个选项并设置题目          [segmentedControl removeSegmentAtIndex:0 animated:NO];//移除指定索引的选项          [segmentedControl setWidth:70.0 forSegmentAtIndex:2];//设置指定索引选项的宽度          [segmentedControl setContentOffset:CGSizeMake(10.0,10.0) forSegmentAtIndex:1];//设置选项中图片等的左上角的位置  //获取指定索引选项的图片imageForSegmentAtIndex:          UIImageView *imageForSegmentAtIndex = [[UIImageView alloc]initWithImage:[segmentedControl imageForSegmentAtIndex:1]];          imageForSegmentAtIndex.frame = CGRectMake(60.0, 100.0, 30.0, 30.0);  //获取指定索引选项的标题titleForSegmentAtIndex          UILabel *titleForSegmentAtIndex = [[UILabel alloc]initWithFrame:CGRectMake(100.0, 100.0, 30.0, 30.0)];          titleForSegmentAtIndex.text = [segmentedControl titleForSegmentAtIndex:0];  //获取总选项数segmentedControl.numberOfSegments          UILabel *numberOfSegments = [[UILabel alloc]initWithFrame:CGRectMake(140.0, 100.0, 30.0, 30.0)];          numberOfSegments.text = [NSString stringWithFormat:@"%d",segmentedControl.numberOfSegments];  //获取指定索引选项的宽度widthForSegmentAtIndex:          UILabel *widthForSegmentAtIndex = [[UILabel alloc]initWithFrame:CGRectMake(180.0, 100.0, 70.0, 30.0)];          widthForSegmentAtIndex.text = [NSString stringWithFormat:@"%f",[segmentedControl widthForSegmentAtIndex:2]];          segmentedControl.selectedSegmentIndex = 2;//设置默认选择项索引          segmentedControl.tintColor = [UIColor redColor];          segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;//设置样式          segmentedControl.momentary = YES;//设置在点击后是否恢复原样                    [segmentedControl setEnabled:NO forSegmentAtIndex:4];//设置指定索引选项不可选          BOOL enableFlag = [segmentedControl isEnabledForSegmentAtIndex:4];//判断指定索引选项是否可选          NSLog(@"%d",enableFlag);          [self.view addSubview:widthForSegmentAtIndex];          [self.view addSubview:numberOfSegments];          [self.view addSubview:titleForSegmentAtIndex];          [self.view addSubview:imageForSegmentAtIndex];          [self.view addSubview:segmentedControl];          [widthForSegmentAtIndex release];          [numberOfSegments release];          [titleForSegmentAtIndex release];          [segmentedTemp release];          [imageForSegmentAtIndex release];  //移除所有选项  //[segmentedControl removeAllSegments];          [super viewDidLoad];      }  /*     // Override to allow orientations other than the default portrait orientation.     - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {         // Return YES for supported orientations         return (interfaceOrientation == UIInterfaceOrientationPortrait);     } */      - (void)didReceiveMemoryWarning {  // Releases the view if it doesn't have a superview.          [super didReceiveMemoryWarning];  // Release any cached data, images, etc that aren't in use.      }      - (void)viewDidUnload {  // Release any retained subviews of the main view.  // e.g. self.myOutlet = nil;      }      - (void)dealloc {          [segmentedControl release];          [super dealloc];      }  @end

转载地址:http://xdmaa.baihongyu.com/

你可能感兴趣的文章
storm shell命令源码分析-shell_submission.clj
查看>>
Hello World
查看>>
域策略事件错误ID 1030 ID 1058
查看>>
DataTable已属于另一个数据集
查看>>
Centos下搭建Nginx
查看>>
Zabbix监控 之初始化配置【3】
查看>>
hillstone 防火墙隐藏命令
查看>>
我的友情链接
查看>>
【跟我学<CCNP>】路由篇之DHCP(续)——DHCP Helper
查看>>
sendfile
查看>>
python控制流
查看>>
进入软件测试要知道的基本概念
查看>>
彻底删除设备驱动
查看>>
redhat9.0在安装oracle10g过程
查看>>
Win7:登陆系统提示group policy client服务未能登陆 拒绝访问
查看>>
新主机安装黑苹果
查看>>
syntax error: unexpected end of file
查看>>
鸟哥-LINUX--(DNS架设)1
查看>>
迭代器模式/Iterator
查看>>
spark--广播变量(Broadcast)源码分析
查看>>