UIkit框架之UISegmentedControl
1.继承链:UIcontrol:UIview:uiresponder:NSObject
2.初始化
(1)- (instancetype)initWithItems:(NSArray *)items
:初始化和返回分段控制器的title或者图片,items:传入选项卡的选项
3.管理分段控制器的内容
(1)- (void)setImage:(UIImage *)image
forSegmentAtIndex:(NSUInteger)segment
:设置某个选项的图片
(2)- (UIImage *)imageForSegmentAtIndex:(NSUInteger)segment
:获取指定索引处的标签图像
(3)- (void)setTitle:(NSString *)title
forSegmentAtIndex:(NSUInteger)segment
:设置指定索引处的标签标题
(4)- (NSString *)titleForSegmentAtIndex:(NSUInteger)segment
:获取指定索引处的标签标题
4.管理分段
(1)- (void)insertSegmentWithImage:(UIImage *)image
atIndex:(NSUInteger)segment
animated:(BOOL)animated
:在指定索引处插入标签图像
(2)- (void)insertSegmentWithTitle:(NSString *)title
atIndex:(NSUInteger)segment
animated:(BOOL)animated
:在指定索引处插入标签标题
(3)@property(nonatomic, readonly) NSUInteger numberOfSegments :获取分段标签的数量
(4)- (void)removeAllSegments :移除所有的分段标签
(5)- (void)removeSegmentAtIndex:(NSUInteger)segment
animated:(BOOL)animated
:移除指定索引处的分段标签
(6)@property(nonatomic) NSInteger selectedSegmentIndex :获取和设置当前被选中的分段标签
5.管理分段标签的行为和显示
(1)@property(nonatomic, getter=isMomentary) BOOL momentary :设置是否保持选中状态
(2)- (void)setEnabled:(BOOL)enabled
forSegmentAtIndex:(NSUInteger)segment
:设置指定索引处标签是否有效(默认有效)
(3)- (BOOL)isEnabledForSegmentAtIndex:(NSUInteger)segment
:获取指定索引处的标签的有效性
(4)- (void)setContentOffset:(CGSize)offset
forSegmentAtIndex:(NSUInteger)segment
:设置指定索引处标签内容偏移量
(5)- (CGSize)contentOffsetForSegmentAtIndex:(NSUInteger)segment
:获取指定索引处的偏移量
(6)- (void)setWidth:(CGFloat)width
forSegmentAtIndex:(NSUInteger)segment
:设置指定索引处标签的宽度
(7)- (CGFloat)widthForSegmentAtIndex:(NSUInteger)segment
:获取指定索引处标签的宽度
(8)@property(nonatomic) BOOL apportionsSegmentWidthsByContent :设置标签宽度是否随内容自适应
6.自定义显示
(1)@property(nonatomic, strong) UIColor *tintColor :设置控件颜色
(2)- (UIImage *)backgroundImageForState:(UIControlState)state
barMetrics:(UIBarMetrics)barMetrics
:获取设定的状态下的segment的背景图像
(3)- (void)setBackgroundImage:(UIImage *)backgroundImage
forState:(UIControlState)state
barMetrics:(UIBarMetrics)barMetrics
:设置设定状态下segment的背景图像
(4)- (UIOffset)contentPositionAdjustmentForSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone
barMetrics:(UIBarMetrics)barMetrics
:获取自定义的标签内容偏移量
(5)- (void)setContentPositionAdjustment:(UIOffset)adjustment
forSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone
barMetrics:(UIBarMetrics)barMetrics
:自行设置标签内容的偏移量
(6)- (UIImage *)dividerImageForLeftSegmentState:(UIControlState)leftState
rightSegmentState:(UIControlState)rightState
barMetrics:(UIBarMetrics)barMetrics
:获取标签之间分割线的图像
(7)- (void)setDividerImage:(UIImage *)dividerImage
forLeftSegmentState:(UIControlState)leftState
rightSegmentState:(UIControlState)rightState
barMetrics:(UIBarMetrics)barMetrics
:设置标签之间分割线的图像
(8)- (NSDictionary *)titleTextAttributesForState:(UIControlState)state
:获取attributes字典
(9)- (void)setTitleTextAttributes:(NSDictionary *)attributes
forState:(UIControlState)state
:通过attributes字典设置设定的状态下标签的标题
7.辅助内容
(1)UISegmentedControlStyle的类型
UISegmentedControlStylePlain, // 有灰色的大白按钮,适合偏好设置单元
UISegmentedControlStyleBordered, // 黑色边界的大白按钮,适用于表格单元
UISegmentedControlStyleBar, // 小按钮,适合导航栏
UISegmentedControlStyleBezeled, //斜角/斜边按钮
(2)UISegmentedControlSegment的类型
UISegmentedControlSegmentAny = 0, //所有标签都受影响
UISegmentedControlSegmentLeft = 1, //只有左边部分受到影响
UISegmentedControlSegmentCenter = 2, //只有中间部分受到影响
UISegmentedControlSegmentRight = 3, //只有右边部分受到影响
UISegmentedControlSegmentAlone = 4, //在只有一个标签时生效