一個(gè)比較好用的第三方分段控制器HMSegmentedControl

類似網(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;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末际看,一起剝皮案震驚了整個(gè)濱河市掌实,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌听想,老刑警劉巖腥刹,帶你破解...
    沈念sama閱讀 222,590評(píng)論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異汉买,居然都是意外死亡衔峰,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén)蛙粘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)垫卤,“玉大人,你說(shuō)我怎么就攤上這事出牧⊙ㄖ猓” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 169,301評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵舔痕,是天一觀的道長(zhǎng)评抚。 經(jīng)常有香客問(wèn)我,道長(zhǎng)伯复,這世上最難降的妖魔是什么慨代? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 60,078評(píng)論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮啸如,結(jié)果婚禮上鱼响,老公的妹妹穿的比我還像新娘。我一直安慰自己组底,他們只是感情好丈积,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,082評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著债鸡,像睡著了一般江滨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上厌均,一...
    開(kāi)封第一講書(shū)人閱讀 52,682評(píng)論 1 312
  • 那天唬滑,我揣著相機(jī)與錄音,去河邊找鬼棺弊。 笑死晶密,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的模她。 我是一名探鬼主播稻艰,決...
    沈念sama閱讀 41,155評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼侈净!你這毒婦竟也來(lái)了尊勿?” 一聲冷哼從身側(cè)響起僧凤,我...
    開(kāi)封第一講書(shū)人閱讀 40,098評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎元扔,沒(méi)想到半個(gè)月后躯保,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,638評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡澎语,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,701評(píng)論 3 342
  • 正文 我和宋清朗相戀三年途事,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片擅羞。...
    茶點(diǎn)故事閱讀 40,852評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡盯孙,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出祟滴,到底是詐尸還是另有隱情振惰,我是刑警寧澤,帶...
    沈念sama閱讀 36,520評(píng)論 5 351
  • 正文 年R本政府宣布垄懂,位于F島的核電站骑晶,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏草慧。R本人自食惡果不足惜桶蛔,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,181評(píng)論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望漫谷。 院中可真熱鬧仔雷,春花似錦、人聲如沸舔示。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,674評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)惕稻。三九已至竖共,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間俺祠,已是汗流浹背公给。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,788評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蜘渣,地道東北人淌铐。 一個(gè)月前我還...
    沈念sama閱讀 49,279評(píng)論 3 379
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像蔫缸,于是被迫代替她去往敵國(guó)和親腿准。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,851評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,322評(píng)論 25 707
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)捂龄、插件释涛、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,124評(píng)論 4 61
  • Short answer: Yes Medium length answer:1.Be sure to recom...
    Crazy2015閱讀 1,311評(píng)論 0 0
  • 一句話說(shuō)出你的目標(biāo):8月—10月三個(gè)月財(cái)富收入七萬(wàn) 動(dòng)機(jī)調(diào)整:籍由我的一切播種動(dòng)作加叁,讓自己的目標(biāo)實(shí)現(xiàn)倦沧,籍由我目標(biāo)的...
    黛兒微笑閱讀 229評(píng)論 0 0
  • 風(fēng)吹過(guò)一些地方展融,響起嗚嗚的聲音時(shí)窖认,那一處好空蕩…… 最喜歡的年紀(jì)是你干什么事都會(huì)被寬恕的年齡,最熱鬧的年間是你不曾...
    scheja芽閱讀 283評(píng)論 0 4