A highly customizable drop-in replacement for UISegmentedControl.

Overview

HMSegmentedControl

Pod Version Carthage compatible Pod Platform Pod License

A highly customizable drop-in replacement for UISegmentedControl, used by more than 22,000 apps, including TikTok, PayPal, Imgur and Bleacher Report.





Features

  • 📸 Supports both text and images
  • ↕️ Multiple sizing and selection styles
  • 📜 Horizontal scrolling for an infinite number of segments
  • ⚙️ Advanced title styling with text attributes for font, color, kerning, shadow, etc
  • 🖥 Compatible with both Swift and Objective-C
  • 📱 Updated for Xcode 11, iOS 13 and Swift 5. Supports all the way back to iOS 7!

Installation

pod 'HMSegmentedControl'

Installation via Carthage is also supported..

Usage

The code below will create a segmented control with the default looks:

let segmentedControl = HMSegmentedControl(sectionTitles: [
    "Trending",
    "News",
    "Library"
])

segmentedControl.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
segmentedControl.addTarget(self, action: #selector(segmentedControlChangedValue(segmentedControl:)), for: .valueChanged)
view.addSubview(segmentedControl)

Included is a demo project showing how to fully customize HMSegmentedControl.

Possible Styles









Apps Using HMSegmentedControl

If you are using HMSegmentedControl in your app or know of an app that uses it, please add it to this list.

Need Help?

If you need help with HMSegmentedControl, or with iOS/Swift development in general, check out swiftmentor.io

License

HMSegmentedControl is licensed under the terms of the MIT License. Please see the LICENSE file for full details.

If this code was helpful, I would love to hear from you.

@HeshamMegid
http://hesh.am

Comments
  • Section titles does not display under iOS10(compatible bug)

    Section titles does not display under iOS10(compatible bug)

    Hi:

    • I have set section titles for my segmentedControl like code below:
    NSArray* titleArray = @[titleOne, titleTwo];
    
        self.segmentCtl = [[AMCustomSegmentedControl alloc] initWithSectionTitles:titleArray];
        [self.segmentCtl setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 42.0f)];
        self.segmentCtl.selectedSegmentIndex = 0;
        self.segmentCtl.selectionIndicatorLocation = AMSegmentedControlSelectionIndicatorLocationDown;
        self.segmentCtl.segmentWidthStyle = AMSegmentedControlSegmentWidthStyleFixed;
        self.segmentCtl.selectionIndicatorColor = [UIColor colorWithRGB:0xE64322];
        self.segmentCtl.selectionStyle = AMSegmentedControlSelectionStyleFullWidthStripe;
        self.segmentCtl.selectionIndicatorHeight = 2.0f;
        self.segmentCtl.borderType = AMSegmentedControlBorderTypeBottom;
        self.segmentCtl.borderColor = [UIColor colorWithRGB:0xE5E5E5];
        self.segmentCtl.titleTextAttributes = @{NSFontAttributeName: SYSTEMFONT(15.0f), NSForegroundColorAttributeName: [UIColor colorWithRGB:0x757575]};
        self.segmentCtl.selectedTitleTextAttributes = @{NSFontAttributeName: SYSTEMFONT(15.0f), NSForegroundColorAttributeName: [UIColor colorWithRGB:0xE64322]};
        [self.segmentCtl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged]
    
    • however, titles does not display under iOS10(as shown below), and everything is well with other versions of system. Anyone can supply some feasible advise or fix this? Thx a lot. img_0027
    opened by lotushacker 16
  • iOS10 setting title attributes causes title hidden

    iOS10 setting title attributes causes title hidden

    self.control.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor],  NSFontAttributeName:[UIFont systemFontOfSize:14]};
    self.control.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName:[UIFont systemFontOfSize:14]};
    [self.control setSectionTitles:@[@"hello", @"loha", @"aloha"]];
    

    title disappears after set title TextAttributes

    opened by yudun1989 11
  • Problem with titleTextAttributes in ios 7.1

    Problem with titleTextAttributes in ios 7.1

    Hi, In ios 7.1 seems that there is a bug setting titleTextAttributes

    self.segControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; in ios 7.1 captura de pantalla 2015-03-03 a las 16 24 47

    In ios 8 captura de pantalla 2015-03-03 a las 16 26 39

    opened by gerardp 11
  • Title and detail

    Title and detail

    Hi

    I wanted to know if there was a possibility to show 2 lines of text. First line would be the section title and, under it, a section "detail". For example, the title would be "Friends" and, under it, the number of friends ?

    Thanks

    opened by rabehssera 9
  • Navigation Controller Problem

    Navigation Controller Problem

    I am using the segmented control with images and a scroll view (segmented control 4 in the demo) and everything is working perfectly except when i use a navigation controller, the area of the segmented control seem to have bigger content are and i can scroll vertically and move around the segmented control items

    opened by masabusharif 9
  • Issue when configured using auto layout and viewDidLoad

    Issue when configured using auto layout and viewDidLoad

    Hi,

    Since the release of 1.3 and the introduction of the scrolling capability we're not able to use HMSegmentedControl in combination with auto layout's constraints.

    We configure our subviews in viewDidLoad and at that time their frame is not determined yet. We use auto layout constraints to have the subviews automatically placed properly. The problem is that when HMSegmentedControl sets the frame of self.scrollView (line 257), self.frame.size.width and self.frame.size.height are equal to 0 making the view invisible.

    Here's an example of our setup:

    - (void)viewDidLoad
    {
      [super viewDidLoad];
    
      HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:sectionTitles];
      segmentedControl.backgroundColor = [UIColor clearColor];
      segmentedControl.textColor = [UIColor grayColor];
      segmentedControl.font = [UIFont boldSystemFontOfSize:16.0f];
    
      segmentedControl.selectedTextColor = [UIColor blackColor];
      segmentedControl.selectionIndicatorHeight = 5.0f;
      segmentedControl.selectionIndicatorColor = [UIColor colorWithHex:0x00A5E4];
      segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
      segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleBox;
      segmentedControl.selectedSegmentIndex = 0;
    
      [self.containerView addSubview:segmentedControl];
      [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[segmentedControl]-0-|"
                                                                                 options:0
                                                                                 metrics:nil
                                                                                   views:@{@"segmentedControl": segmentedControl}]];
      [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[segmentedControl]-0-|"
                                                                                 options:0
                                                                                 metrics:nil
                                                                                   views:@{@"segmentedControl": segmentedControl}]];
    }
    

    Note: self.containerView is already a subview of self.view through the storyboard

    opened by sguillope 8
  • Add Swift Package Manager support

    Add Swift Package Manager support

    Thanks for sharing this library @HeshamMegid.

    I am using SPM for my projects and figured it will be valuable for others who are using SPM if you add Package.swift to this project.

    opened by raxityo 7
  • How to customize the segment size and the section title font and size -

    How to customize the segment size and the section title font and size -

    I am doing a segmented control using HMsegmentedControl. My title for the segments vary in their length. So my question is that Can I change the font as well as can I wordwrap the titles width to length of my content ? You could check my image attached. For eg - I want the width of car segment be wrapped to its length not more than that. image

    opened by gabhisekdev 7
  • <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0

    : CGContextSetStrokeColorWithColor: invalid context 0x0

    Environment: Ipad3, ios7

    : CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

    opened by purkylin 7
  • HMSegmentedControlTypeTextImages icon alignment

    HMSegmentedControlTypeTextImages icon alignment

    I think the icons should be at the left of the labels... not in the middle.

    hmsegmentedcontrol

     _segmentedControl = [[HMSegmentedControl alloc]
                             initWithSectionImages:@[[UIImage imageNamed:@"place_25"],[UIImage imageNamed:@"directions_16"]]
                             sectionSelectedImages:@[[UIImage imageNamed:@"place_25"],[UIImage imageNamed:@"directions_16"]]
                             titlesForSections:@[@"Place"),@"Directions"]];
    
        _segmentedControl.frame = CGRectMake(0.0f, 0.0f, frame.size.width, 40.0f);
        _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
        _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
        _segmentedControl.selectionIndicatorColor = [UIColor CycleMapColor];
        _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor cm_veryDarkGrayColor],
                                                  NSFontAttributeName : [UIFont CycleMapBoldFontOfSize:12.0f]};
        _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor CycleMapColor]};
    
    opened by rousseauo 6
  • Attributed title display issue

    Attributed title display issue

        NSDictionary *attributed = @{NSForegroundColorAttributeName : [UIColor whiteColor],
                                     NSFontAttributeName : [UIFont systemFontOfSize:16.f]};
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Title" attributes:attributed];
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        attachment.image = [UIImage imageNamed:@"img_segmented_chevron_highlight"];
        NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attachment];
        [string appendAttributedString:attachString];
    

    My question is the attachment not display.

    opened by shiablue 5
  • HMSegmentedControl Lower Version installation

    HMSegmentedControl Lower Version installation

    I'm Unable to install lower version of HMSegmentedControl. even i have added tag number in pod but on pod installation it's downloading just latest one. I want to install 1.5.4 but its installing 1.5.6. Please let me know ho can i install just 1.5.4 version? Thanks

    opened by usman643 0
  • Testing HMSegmentedControl with Appium

    Testing HMSegmentedControl with Appium

    Hello, I need to separately locate each button on controller. As well for each button need to add attribute like "checked = True/False" to verify which tab is active at the moment. Currently all of them under single object - XCUIElementTypeScrollView.

    Please refer screenshot for more details Screenshot 2022-02-04 at 3 28 31 PM .

    opened by gopal-patil 0
  • Section Image not showing.

    Section Image not showing.

    Xcode Version: 13 Swift 5 HMSegementedControl Version: 1.5.6

    Section Images and titles gets assigned but only the titles shows up and the images do not. ` private func setupPageControls() {

    	let image = UIImage(named: "indicator-red")!.withRenderingMode(.alwaysOriginal)
    	let images = [image, image, image]
    
    	let segmentedControl = HMSegmentedControl(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 44))
    	view.addSubview(segmentedControl)
    	segmentedControl.autoSetDimension(.height, toSize: 44)
    	segmentedControl.autoPinEdge(toSuperviewEdge: .left)
    	segmentedControl.autoPinEdge(toSuperviewEdge: .right)
    	segmentedControl.autoPinEdge(toSuperviewEdge: .top)
    
    	segmentedControl.sectionImages = images
    	segmentedControl.imagePosition = .leftOfText
    
    	if let fmt = self.configSegmentedControlTitleFormatter() {
    		segmentedControl.titleFormatter = fmt
    	}
    	self.segmentedControl = segmentedControl
    
    	let page = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
    	page.willMove(toParent: self)
    	view.addSubview(page.view)
    	addChild(page)
    	page.didMove(toParent: self)
    
    	page.view.autoPinEdge(.left, to: .left, of: view)
    	page.view.autoPinEdge(.right, to: .right, of: view)
    	page.view.autoPinEdge(.top, to: .bottom, of: segmentedControl)
    	page.view.autoPinEdge(.bottom, to: .bottom, of: view)
    
    	page.delegate = self
    	page.dataSource = self
    	self.pageController = page
    
    }`
    
    opened by minon250 0
  • Avoid Xcode 12 warning -> move to iOS 9

    Avoid Xcode 12 warning -> move to iOS 9

    Usage Details

    Language: Swift Platform: iPhone iOS Version: iOS 9 - 14

    Expected Behavior

    Xcode 12 build without warnings, proposal to move target to iOS 9

    Actual Behavior

    Xcode 12.x warning The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99.

    Steps to Reproduce the Problem

    Use latest Xcode 12 or 12.0.1 Use TPKeyboardAvoiding in a Swift project with target iOS 11

    opened by tbechtum 1
Releases(v1.5.6)
  • v1.5.6(May 11, 2020)

  • v1.5.4(May 20, 2017)

  • v1.5.3(Sep 17, 2016)

  • v1.5.1(Mar 30, 2015)

  • v1.5(Mar 3, 2015)

    • Adds advanced styling support for default and selected state with ability to customize kerning, shadow, stroke color and width, ligature, baseline offset, paragraph style, etc.
    • A few of the control style attributes can now be customized using UIAppearance.
    • Adds ability to specify a border type, color and width.
    • Drops support for older iOS versions. Now works with iOS 7 and above.
    • Lots of bug fixes.
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Aug 14, 2014)

    • Lots of bug fixes
    • Add AutoLayout support
    • Adds HMSegmentedControlSelectionStyleArrow
    • Adds support for non-animated selections.
    • Adds support for custom box layer opacity.
    • Add support for multi-line labels on iOS 7+
    • Updated documentation in header file
    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Nov 19, 2013)

    • Introducing horizontal scrolling via scrollEnabled property. Check example project
    • Adds XIB/Storyboard support
    • Fixes deprecations when building with iOS 7 SDK
    • Updates example project to support iOS 7
    • Code refactoring and cleanup
    Source code(tar.gz)
    Source code(zip)
Owner
Hesham Abd-Elmegid
Engineering @Instabug. Previously, Swift Mentor @CareerFoundry.
Hesham Abd-Elmegid
Custom UISegmentedControl replacement for iOS, written in Swift

TwicketSegmentedControl Custom UISegmentedControl replacement for iOS, written in Swift, used in the Twicket app. It handles the inertia of the moveme

Pol Quintana 1.7k Dec 31, 2022
UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.

MultiSelectSegmentedControl UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images. Feature

Yonat Sharon 286 Dec 15, 2022
MacSegmentedControl - UISegmentedControl on macOS

Mac Segmented Control An implementation of iOS' UISegmentedControl on macOS. Add

Jeff Dlouhy 0 Dec 30, 2021
Customizable segmented control with interactive animation.

LUNSegmentedControl Purpose LUNSegmentedControl is control designed to let developers use segmented control with custom appearance, customizable inter

Stormotion 346 Dec 25, 2021
AKASegmentedControl is a fully customizable Segmented Control for iOS

#AKASegmentedControl AKASegmentedControl is a fully customizable Segmented Control for iOS ##Preview ##Usage Installation CocoaPods You can use CocoaP

Ali Karagoz 389 Sep 1, 2022
A customizable Segmented Control for iOS. Supports text and image.

YUSegment 中文文档 A customizable segmented control for iOS. Features Supports both (Attributed)text and image Supports show separator Supports hide indic

YyGgQq 112 Jun 10, 2022
An easy to use, customizable replacement for UISegmentedControl & UISwitch.

BetterSegmentedControl BetterSegmentedControl is an easy to use, customizable replacement for UISegmentedControl and UISwitch written in Swift. Featur

George Marmaridis 2k Dec 30, 2022
Custom UISegmentedControl replacement for iOS, written in Swift

TwicketSegmentedControl Custom UISegmentedControl replacement for iOS, written in Swift, used in the Twicket app. It handles the inertia of the moveme

Pol Quintana 1.7k Dec 31, 2022
UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics

The YLProgressBar is an UIProgressView replacement with a highly and fully customizable animated progress bar in pure Core Graphics. It has been imple

Yannick Loriot 1.3k Jan 5, 2023
Highly customizable drop-in solution for introduction views.

EAIntroView - simple iOS Introductions This is highly customizable drop-in solution for introduction views. Some features (remember, most features are

Evgeny Aleksandrov 3.8k Dec 17, 2022
A replacement for as which runs in constant time instead of O(n) when the conformance is not satisfiedA replacement for as which runs in constant time instead of O(n) when the conformance is not satisfied

ZConform A replacement for as? which runs in constant time instead of O(n) when the conformance is not satisfied. How it works ZConform does a one-tim

Emerge Tools 20 Aug 4, 2022
UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.

MultiSelectSegmentedControl UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images. Feature

Yonat Sharon 286 Dec 15, 2022
UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.

MultiSelectSegmentedControl UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images. Feature

Yonat Sharon 286 Dec 15, 2022
MacSegmentedControl - UISegmentedControl on macOS

Mac Segmented Control An implementation of iOS' UISegmentedControl on macOS. Add

Jeff Dlouhy 0 Dec 30, 2021
CollectionViewSegmentedControl - Scrollable UISegmentedControl built using a UICollectionView

CollectionViewSegmentedControl Installation CocoaPods Download CocoaPods Run 'Po

James Sedlacek 7 Nov 24, 2022
The missing UIKit component. A scrollable alternative to UISegmentedControl

Requirements iOS 15.0 and higher Installation Swift Package Manager: dependencies: [ .package(url: "https://github.com/hugo-pivaral/UITabControl.git

Hugo Pivaral 11 Nov 18, 2022
UILabel drop-in replacement supporting Hashtags

ActiveLabel.swift UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://), Emails and custom regex patterns, written in Swif

Optonaut 4.2k Dec 31, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Jan 8, 2023
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Pavel Sharanda 1.1k Dec 26, 2022