Latest 1.0.1
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit

[Pod Version]()
Carthage compatible
[Pod Platform]()
[Pod License]()


A customizable segmented control for iOS.



  • Supports both (Attributed)text and image
  • Supports show separator
  • Supports hide indicator
  • Indicator could be located at the top and bottom
  • YUSegment works on iOS 8.0+ and is compatible with ARC projects



  1. Add a pod entry to your Podfile pod 'YUSegment'
  2. Running pod install
  3. #import <YUSegment/YUSegment.h> where you need


github "afishhhhh/YUSegment"


YUSegmentedControl inherits from UIControl, supports Target-Action.

YUSegmentedControl *segmentedControl = [[YUSegmentedControl alloc] initWithTitles:@[@"健身", @"摄影", @"科技", @"美食", @"旅行"]];
[self.view addSubview:segmentedControl];
[segmentedControl addTarget:self action:@selector(segmentedControlTapped:) forControlEvents:UIControlEventValueChanged];

By default, the background color of segmented control is whiteColor, the color of indicator is darkGrayColor, the height of indicator is 3.0, the color of separator is #e7e7e7.



- (instancetype)initWithTitles:(NSArray <NSString *> *)titles;
- (instancetype)initWithImages:(NSArray <UIImage *> *)images;
- (instancetype)initWithImages:(NSArray <UIImage *> *)images
                selectedImages:(nullable NSArray <UIImage *> *)selectedImages;

You can use selectedImages if you want to show different images when a specific segment selected.

- (nullable NSString *)titleAtIndex:(NSUInteger)index;
- (nullable UIImage *)imageAtIndex:(NSUInteger)index;

You can get the corresponding text or image based on a specific index.

- (void)showBadgeAtIndexes:(NSArray <NSNumber *> *)indexes;
- (void)hideBadgeAtIndex:(NSUInteger)index;


[segmentedControl show BadgeAtIndexes:@[@1, @2]];

- (void)setTextAttributes:(nullable NSDictionary *)attributes 

The attributes for text. For a list of attributes that you can include in this dictionary, see Character Attributes.
The value of state could be YUSegmentedControlNormal and YUSegmentedControlSelected.


[segmentedControl setTextAttributes:@{
  NSFontAttributeName: [UIFont systemFontOfSize:20.0 weight:UIFontWeightLight],
  NSForegroundColorAttributeName: [UIColor blackColor]
} forState:YUSegmentedControlNormal];


  • numberOfSegments(NSUInteger, readonly)

     return the number of segments in a segmented control.

  • selectedSegmentIndex(NSUInteger, readonly)

    The index number identifying the selected segment. Default is 0.

  • horizontalPadding

    Default is 0.


     If assign it to 32.0.


  • showsTopSeparator

    A Boolean value that controls whether the top separator is visible. Default is YES.

  • showsBottomSeparator

    A Boolean value that controls whether the bottom separator is visible. Default is YES.

  • showsVerticalDivider

    A Boolean value that controls whether the vertical divider is visible. Default is NO.

  • showsIndicator

    A Boolean value that controls whether the indicator is visible. Default is YES.

  • backgroundColor(YUSegmentedControl)

    The background color of segmented control. Default is white.

  • height(YUSegmentedControlIndicator)

    The height of indicator. Default is 3.0.
    You should use this property like this:

    segment.indicator.height = 3.0;
  • locate(YUSegmentedControlIndicator)

    The vertical alignment of indicator. Default is YUSegmentedControlIndicatorLocateBottom. Also could be YUSegmentedControlIndicatorLocateTop
    You should use this property like this:

    segment.indicator.locate = YUSegmentedControlIndicatorLocateTop;
  • backgroundColor(YUSegmentedControlIndicator)

    The background color of indicator. Default is dark gray.
    You should use this property like this:

    segment.indicator.backgroundColor = [UIColor whiteColor];


This code is distributed under the terms and conditions of the MIT license.

Latest podspec

    "name": "YUSegment",
    "version": "1.0.1",
    "summary": "A customizable Segmented Control for iOS. Supports text and image.",
    "description": "#YUSegmentnnA customizable **Segmented Control** for iOS. Supports text and image.nn##RequirementsnnYUSegment works on iOS 8.0 and later version and is compatible with ARC projects.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "afishhhhh": "[email protected]"
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "1.0.1"
    "source_files": [
    "frameworks": "UIKit",
    "requires_arc": true

Pin It on Pinterest

Share This