我们提供的服务有:网站制作、成都网站制作、微信公众号开发、网站优化、网站认证、张家港ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的张家港网站制作公司> 1 1.segmentedControlStyle
2 设置segment的显示样式。
3 typedef NS_ENUM(NSInteger, UISegmentedControlStyle) {
4 UISegmentedControlStylePlain, // large plain 系统默认平板样式 5 segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
6
7 UISegmentedControlStyleBordered,// large bordered 黑边样式 8 segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
9
10 UISegmentedControlStyleBar, // small button/nav bar style. Tintable 条状样式11 segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
12
13 UISegmentedControlStyleBezeled, // DEPRECATED. Do not use this style. 这个类型不要使用,用了会报错喔。14 };
15
16 2.tintColor 渐变颜色
17 Default tintColor is nil. Only used if style is UISegmentedControlStyleBar
18 默认空,只有使用UISegmentedControlStyleBar,才能设置渐变颜色。
19 segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
20 segmentedControl.tintColor = [UIColor redColor];
21 效果:
22
23
24 3.momentary 设置在点击后是否恢复原样
25 默认为NO
26 segmentedControl.momentary = No;
27
28 点击之后效果:
29
30 segmentedControl.momentary = YES;
31 点击之后效果:
32
33
34
35 4. numberOfSegments(只读)
36 获取总选项数segmentedControl.numberOfSegments
37
38 5. selectedSegmentIndex
39 用来设置选中项或者返回选中项。
40 segmentedControl.selectedSegmentIndex = 2;//设置默认选择项索引41 segmentedControl.selectedSegmentIndex // 获取选中项42 6.- (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment;
43 [segmentedControl setTitle:@"two" forSegmentAtIndex:1];//设置指定索引的题目44 效果:
45
46 7. - (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment;
47 [segmentedControl setImage:[UIImage imageNamed:@"lan.png"] forSegmentAtIndex:3];//设置指定索引的图片48 8.-(void)insertSegmentWithTitle:(NSString*)title atIndex:(NSUInteger)segment animated:(BOOL)animated;
49 [segmentedControl insertSegmentWithTitle:@"add" atIndex:3 animated:NO];//在指定索引插入一个选项并设置题目50 效果:
51
52 9.-(void)insertSegmentWithImage:(UIImage *)image atIndex:(NSUInteger)segment animated:(BOOL)animated;
53 [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"mei.png"] atIndex:2 animated:NO];//在指定索引插入一个选项并设置图片54
55 10.- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated;
56 [segmentedControl removeSegmentAtIndex:0 animated:NO];//移除指定索引的选项57 效果:
58
59 11. - (void)removeAllSegments;
60 //移除所有选项
61 //[segmentedControl removeAllSegments];62
63 12. - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment; // set to 0.0 width to autosize. default is 0.064 选项卡的宽度默认为0,此方法能够设置选项卡宽度。
65 [segmentedControl setWidth:70.0 forSegmentAtIndex:2];//设置指定索引选项的宽度66
67 效果:
68
69 13. - (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment; // adjust offset of image or text inside the segment. default is (0,0)70 [segmentedControl setContentOffset:CGSizeMake(10,0) forSegmentAtIndex:1];
71 设置选项卡内部文字或者图片与默认位置的偏移量,默认位置在选项卡的中心。
72 效果:
73
74 14. - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment;
75
76 [segmentedControl setEnabled:NO forSegmentAtIndex:4];//设置指定索引选项不可选77
78 15.增加事件响应机制
79 监听的是这个事件:UIControlEventValueChanged,值改变事件
80
81 [segmentedControl addTarget:self action:@selector(itemClick) forControlEvents:UIControlEventValueChanged];