iOS7 UISegmentedControl

####iOS7 Programming Cookbook 第一章学习笔记 UISegmentedControl

#####Grouping Compact Options with UISegmentedControl

#####ViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- (void)viewDidLoad{
[super viewDidLoad];
//设置背景色白色
self.view.backgroundColor = [UIColor whiteColor];

//创建数组segments
NSArray *segments = @[@"iPhone",[UIImage imageNamed:@"iPad.png"],@"iPod",@"iMac"];
// NSArray *segments = [[NSArray alloc] initWithObjects:@"iPhone", [UIImage imageNamed:@"iPad.png"],@"iPod",@"iMac", nil];

self.mySegmentedControl = [[UISegmentedControl alloc]
initWithItems:segments];

//iOS7 Deprecated
// self.mySegmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;

//声明segmentedFrame坐标
CGRect segmentedFrame = self.mySegmentedControl.frame;
//高和宽
segmentedFrame.size.height = 64.0f;
segmentedFrame.size.width = 300.0f;
//设置新的segmentedFrame为mySegmentedControl.frame
self.mySegmentedControl.frame = segmentedFrame;
//中间显示
self.mySegmentedControl.center = self.view.center;
//添加到view
[self.view addSubview:self.mySegmentedControl];
}

Reference

坚持原创技术分享,您的支持将鼓励我继续创作!
0%