類似網(wǎng)易新聞的首頁(yè)等,這種東西還是比較常用的,總結(jié)了一下提供的外部屬性和方法,基本能滿足日常開(kāi)發(fā)
簡(jiǎn)單記錄一下吧,對(duì)屬性進(jìn)行基本測(cè)試吧,也不寫(xiě)別的了,官方Demo都有
#import <UIKit/UIKit.h>
@class HMSegmentedControl;
typedef void (^IndexChangeBlock)(NSInteger index);
typedef NSAttributedString *(^HMTitleFormatterBlock)(HMSegmentedControl *segmentedControl, NSString *title, NSUInteger index, BOOL selected);
typedef enum {
HMSegmentedControlSelectionStyleTextWidthStripe, // Indicator width will only be as big as the text width // 下面的橫條跟字體一般大
HMSegmentedControlSelectionStyleFullWidthStripe, // Indicator width will fill the whole segment // 下面的橫條跟按鈕大小一般大
HMSegmentedControlSelectionStyleBox, // A rectangle that covers the whole segment // 點(diǎn)擊之后按鈕背景會(huì)有凹陷效果
HMSegmentedControlSelectionStyleArrow // An arrow in the middle of the segment pointing up or down depending on `HMSegmentedControlSelectionIndicatorLocation` // 選中出現(xiàn)個(gè)三角,枚舉值,頂部出現(xiàn),下部出現(xiàn),不出現(xiàn)
} HMSegmentedControlSelectionStyle; // 選中樣式
typedef enum {
HMSegmentedControlSelectionIndicatorLocationUp, // 頂上出現(xiàn)
HMSegmentedControlSelectionIndicatorLocationDown, // 底部出現(xiàn)
HMSegmentedControlSelectionIndicatorLocationNone // No selection indicator // 不出現(xiàn)
} HMSegmentedControlSelectionIndicatorLocation; // 選中出現(xiàn)一個(gè)三角
typedef enum {
HMSegmentedControlSegmentWidthStyleFixed, // Segment width is fixed // 自動(dòng)填充整個(gè)寬度
HMSegmentedControlSegmentWidthStyleDynamic, // Segment width will only be as big as the text width (including inset) // 根據(jù)最大文字算出寬度,自適應(yīng)
} HMSegmentedControlSegmentWidthStyle; // 設(shè)置按鈕大小樣式的
typedef NS_OPTIONS(NSInteger, HMSegmentedControlBorderType) {
HMSegmentedControlBorderTypeNone = 0,
HMSegmentedControlBorderTypeTop = (1 << 0),
HMSegmentedControlBorderTypeLeft = (1 << 1),
HMSegmentedControlBorderTypeBottom = (1 << 2),
HMSegmentedControlBorderTypeRight = (1 << 3)
};
enum {
HMSegmentedControlNoSegment = -1 // Segment index for no selected segment
};
typedef enum {
HMSegmentedControlTypeText,
HMSegmentedControlTypeImages,
HMSegmentedControlTypeTextImages
} HMSegmentedControlType; // 選擇按鈕放的東西
@interface HMSegmentedControl : UIControl
@property (nonatomic, strong) NSArray *sectionTitles;
@property (nonatomic, strong) NSArray *sectionImages;
@property (nonatomic, strong) NSArray *sectionSelectedImages;
/**
Provide a block to be executed when selected index is changed.
Alternativly, you could use `addTarget:action:forControlEvents:`
*/
// 就是添加事件
@property (nonatomic, copy) IndexChangeBlock indexChangeBlock;
/**
Used to apply custom text styling to titles when set.
When this block is set, no additional styling is applied to the `NSAttributedString` object returned from this block.
*/
@property (nonatomic, copy) HMTitleFormatterBlock titleFormatter; // 自定義的樣式
/**
Text attributes to apply to item title text.
*/
@property (nonatomic, strong) NSDictionary *titleTextAttributes UI_APPEARANCE_SELECTOR;
/*
Text attributes to apply to selected item title text.
Attributes not set in this dictionary are inherited from `titleTextAttributes`.
*/
@property (nonatomic, strong) NSDictionary *selectedTitleTextAttributes UI_APPEARANCE_SELECTOR;
/**
Segmented control background color.
Default is `[UIColor whiteColor]`
*/
@property (nonatomic, strong) UIColor *backgroundColor UI_APPEARANCE_SELECTOR;
/**
Color for the selection indicator stripe/box
Default is `R:52, G:181, B:229`
*/
@property (nonatomic, strong) UIColor *selectionIndicatorColor UI_APPEARANCE_SELECTOR;
/**
Color for the vertical divider between segments.
Default is `[UIColor blackColor]`
*/
@property (nonatomic, strong) UIColor *verticalDividerColor UI_APPEARANCE_SELECTOR; // 兩個(gè)按鈕之間分割線顏色
/**
Opacity for the seletion indicator box.
Default is `0.2f`
*/
@property (nonatomic) CGFloat selectionIndicatorBoxOpacity; // 不透明的盒子對(duì)比指標(biāo)。
/**
Width the vertical divider between segments that is added when `verticalDividerEnabled` is set to YES.
Default is `1.0f`
*/
@property (nonatomic, assign) CGFloat verticalDividerWidth;// 兩個(gè)按鈕之間分割線寬度
/**
Specifies the style of the control
Default is `HMSegmentedControlTypeText`
*/
@property (nonatomic, assign) HMSegmentedControlType type;
/**
Specifies the style of the selection indicator.
Default is `HMSegmentedControlSelectionStyleTextWidthStripe`
*/
@property (nonatomic, assign) HMSegmentedControlSelectionStyle selectionStyle; // 指定的標(biāo)識(shí)樣式
/**
Specifies the style of the segment's width.
Default is `HMSegmentedControlSegmentWidthStyleFixed`
*/
@property (nonatomic, assign) HMSegmentedControlSegmentWidthStyle segmentWidthStyle; // 指定按鈕樣式
/**
Specifies the location of the selection indicator.
Default is `HMSegmentedControlSelectionIndicatorLocationUp`
*/
@property (nonatomic, assign) HMSegmentedControlSelectionIndicatorLocation selectionIndicatorLocation; // 指定指示標(biāo)出現(xiàn)位置
/*
Specifies the border type.
Default is `HMSegmentedControlBorderTypeNone`
*/
@property (nonatomic, assign) HMSegmentedControlBorderType borderType; // 指定邊界類型阵幸。
/**
Specifies the border color.
Default is `[UIColor blackColor]`
*/
@property (nonatomic, strong) UIColor *borderColor; // 指定邊框顏色。
/**
Specifies the border width.
Default is `1.0f`
*/
@property (nonatomic, assign) CGFloat borderWidth;
/**
Default is YES. Set to NO to deny scrolling by dragging the scrollView by the user.
*/
@property(nonatomic, getter = isUserDraggable) BOOL userDraggable; // 默認(rèn)是肯定的凤壁。將沒(méi)有拒絕滾動(dòng)通過(guò)拖動(dòng)滾動(dòng)視圖的用戶遣耍。
/**
Default is YES. Set to NO to deny any touch events by the user.
*/
@property(nonatomic, getter = isTouchEnabled) BOOL touchEnabled; // 是否點(diǎn)擊
/**
Default is NO. Set to YES to show a vertical divider between the segments.
*/
@property(nonatomic, getter = isVerticalDividerEnabled) BOOL verticalDividerEnabled; // 分割線顯示還是不顯示
/**
Index of the currently selected segment.
*/
@property (nonatomic, assign) NSInteger selectedSegmentIndex; // 當(dāng)前選擇的標(biāo)號(hào),從0開(kāi)始
/**
Height of the selection indicator. Only effective when `HMSegmentedControlSelectionStyle` is either `HMSegmentedControlSelectionStyleTextWidthStripe` or `HMSegmentedControlSelectionStyleFullWidthStripe`.
Default is 5.0
*/
@property (nonatomic, readwrite) CGFloat selectionIndicatorHeight; // 被選擇的小標(biāo)高度
/**
Edge insets for the selection indicator.
NOTE: This does not affect the bounding box of HMSegmentedControlSelectionStyleBox
When HMSegmentedControlSelectionIndicatorLocationUp is selected, bottom edge insets are not used
When HMSegmentedControlSelectionIndicatorLocationDown is selected, top edge insets are not used
Defaults are top: 0.0f
left: 0.0f
bottom: 0.0f
right: 0.0f
*/
@property (nonatomic, readwrite) UIEdgeInsets selectionIndicatorEdgeInsets; // 選擇框包邊
/**
Inset left and right edges of segments.
Default is UIEdgeInsetsMake(0, 5, 0, 5)
*/
@property (nonatomic, readwrite) UIEdgeInsets segmentEdgeInset; // 插圖左派和右派的邊緣部分蒋得。
/**
Default is YES. Set to NO to disable animation during user selection.
*/
@property (nonatomic) BOOL shouldAnimateUserSelection; // 選擇變動(dòng)的動(dòng)畫(huà)
- (id)initWithSectionTitles:(NSArray *)sectiontitles;
- (id)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages;
- (instancetype)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages titlesForSections:(NSArray *)sectiontitles;
- (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated;
- (void)setIndexChangeBlock:(IndexChangeBlock)indexChangeBlock;
- (void)setTitleFormatter:(HMTitleFormatterBlock)titleFormatter;