基本控件文档-UISegment属性----iOS-Apple苹果官方文档翻译

本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址

//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495956.html

本文对应pdf文档下载链接,猛戳—>:

 UISegment属性.pdf
190.7 KB

 

 


UISegment属性
技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong  
1.segmentedControlStyle
设置segment的显示样式。
typedef NS_ENUM(NSInteger, UISegmentedControlStyle) {
UISegmentedControlStylePlain,    
 // large plain 系统默认平板样式
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
pastedGraphic.png
UISegmentedControlStyleBordered, 
 // large bordered 黑边样式
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
pastedGraphic_1.png
UISegmentedControlStyleBar,      
 // small button/nav bar style. Tintable 条状样式
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
pastedGraphic_2.png
    UISegmentedControlStyleBezeled,  
 // DEPRECATED. Do not use this style. 这个类型不要使用,用了会报错喔。
};
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495956.html
2.tintColor 渐变颜色
Default tintColor is nil. Only used if style is UISegmentedControlStyleBar
默认空,只有使用UISegmentedControlStyleBar,才能设置渐变颜色。
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor = [UIColor redColor];
效果:
pastedGraphic_3.png
 
3.momentary 设置在点击后是否恢复原样
默认为NO
segmentedControl.momentary = No;

点击之后效果:
pastedGraphic_4.png
segmentedControl.momentary = YES;
点击之后效果:
pastedGraphic_5.png


4. numberOfSegments(只读)
获取总选项数segmentedControl.numberOfSegments

5. selectedSegmentIndex
用来设置选中项或者返回选中项。
segmentedControl.selectedSegmentIndex = 2;//设置默认选择项索引
segmentedControl.selectedSegmentIndex // 获取选中项
6.- (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment;
[segmentedControl setTitle:@"two" forSegmentAtIndex:1];//设置指定索引的题目
效果:
pastedGraphic_6.png
7.
 - (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment;       
[segmentedControl setImage:[UIImage imageNamed:@"lan.png"] forSegmentAtIndex:3];//设置指定索引的图片
8.-(void)insertSegmentWithTitle:(NSString*)title atIndex:(NSUInteger)segment animated:(BOOL)animated;
[segmentedControl insertSegmentWithTitle:@"add" atIndex:3 animated:NO];//在指定索引插入一个选项并设置题目
效果:
pastedGraphic_7.png
9.
-(void)insertSegmentWithImage:(UIImage *)image  atIndex:(NSUInteger)segment animated:(BOOL)animated;
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"mei.png"] atIndex:2 animated:NO];//在指定索引插入一个选项并设置图片
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495956.html
10.- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated;
[segmentedControl removeSegmentAtIndex:0 animated:NO];//移除指定索引的选项
效果:
pastedGraphic_8.png
技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong  
11. - (void)removeAllSegments;
    //移除所有选项
//[segmentedControl removeAllSegments];

12. - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;         // set to 0.0 width to autosize. default is 0.0
选项卡的宽度默认为0,此方法能够设置选项卡宽度。
[segmentedControl setWidth:70.0 forSegmentAtIndex:2];//设置指定索引选项的宽度

效果:
pastedGraphic_9.png
技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong  
13. - (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment; // adjust offset of image or text inside the segment. default is (0,0)
[segmentedControl setContentOffset:CGSizeMake(10,0) forSegmentAtIndex:1];
设置选项卡内部文字或者图片与默认位置的偏移量,默认位置在选项卡的中心。
效果:
pastedGraphic_10.png
14. - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment;       

[segmentedControl setEnabled:NO forSegmentAtIndex:4];//设置指定索引选项不可选

15.增加事件响应机制
监听的是这个事件:UIControlEventValueChanged,值改变事件

[
segmentedControladdTarget:selfaction:@selector(itemClick)forControlEvents:UIControlEventValueChanged];

本文对应pdf文档下载链接,猛戳—>:https://www.evernote.com/shard/s227/sh/5505166b-55c5-4a55-be1a-f794149a0513/644f115f9faf61c5307ca0d073b513a5

//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495956.html

本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址



作者:
出处:http://www.cnblogs.com/ChenYilong/(点击RSS订阅)
本文版权归作者和博客园共有,欢迎转载,
但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/ChenYilong/p/3495956.html