HMSegmentedControl的使用

来源:互联网 发布:基数排序算法 编辑:程序博客网 时间:2024/05/01 11:22



下载地址:https://github.com/HeshamMegid/HMSegmentedControl  


    HMSegmentedControl *segmented = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"已收公告",@"已发公告"]];    segmented.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; // 自动调整    segmented.frame = CGRectMake(self.view.bounds.size.width/2-100, 4, 200, 40);    segmented.backgroundColor = [UIColor clearColor];    segmented.selectionIndicatorHeight = 3.0f;  // 线的高度    segmented.font = [UIFont fontWithName:@"STHeitiSC-Light" size:19.0f];  // 设置字体    segmented.textColor = WHRGB(255, 175, 185);   // 字的颜色    segmented.selectedTextColor = [UIColor whiteColor]; // 选中时字体颜色    segmented.selectionIndicatorColor = [UIColor whiteColor];  //线条的颜色    segmented.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe; //线充满整个长度    segmented.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown; //线的位置    [segmented addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];    self.segmentedControl = segmented;    [self.navigationController.navigationBar addSubview:segmented];</span>



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


    HMSegmentedControlSelectionStyleArrow // An arrow in the middle of the segment pointing up or down depending on `HMSegmentedControlSelectionIndicatorLocation`


} HMSegmentedControlSelectionStyle;


typedef enum {  // 线的位置

    HMSegmentedControlSelectionIndicatorLocationUp,


    HMSegmentedControlSelectionIndicatorLocationDown,

HMSegmentedControlSelectionIndicatorLocationNone// No selection indicator

} HMSegmentedControlSelectionIndicatorLocation;



//  边缘的样式

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;





// 设置内容

@property (nonatomic,strong)NSArray *sectionTitles;

@property (nonatomic,strong)NSArray *sectionImages;

@property (nonatomic,strong)NSArray *sectionSelectedImages;


// 判断点击是哪个

@property (nonatomic,assign)NSInteger selectedSegmentIndex;


1 0