AKASegmentedControl is a fully customizable Segmented Control for iOS

Overview

#AKASegmentedControl

AKASegmentedControl is a fully customizable Segmented Control for iOS

##Preview preview

##Usage

Installation

CocoaPods

You can use CocoaPods to install AKASegmentedControl by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'AKASegmentedControl'

To get the full benefits import AKASegmentedControl.h wherever you import UIKit

#import "AKASegmentedControl.h"

Manually

  1. Download and drop /AKASegmentedControl folder in your project.
  2. Congratulations!

Usage

// Initialization of the segmented control
AKASegmentedControl *segmentedControl = [[AKASegmentedControl alloc] initWithFrame:aRect]
[segmentedControl addTarget:self action:@selector(segmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];

// Setting the resizable background image
UIImage *backgroundImage = [[UIImage imageNamed:@"segmented-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
[segmentedControl setBackgroundImage:backgroundImage];

// Setting the content edge insets to adapte to you design
[segmentedControl setContentEdgeInsets:UIEdgeInsetsMake(2.0, 2.0, 3.0, 2.0)];

// Setting the behavior mode of the control
[segmentedControl setSegmentedControlMode:AKASegmentedControlModeSticky];

// Setting the separator image
[segmentedControl setSeparatorImage:[UIImage imageNamed:@"segmented-separator.png"]];

UIImage *buttonBackgroundImagePressedLeft = [[UIImage imageNamed:@"segmented-bg-pressed-left.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 4.0, 0.0, 1.0)];
UIImage *buttonBackgroundImagePressedCenter = [[UIImage imageNamed:@"segmented-bg-pressed-center.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 4.0, 0.0, 1.0)];
UIImage *buttonBackgroundImagePressedRight = [[UIImage imageNamed:@"segmented-bg-pressed-right.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 1.0, 0.0, 4.0)];

// Button 1
UIButton *buttonSocial = [[UIButton alloc] init];
UIImage *buttonSocialImageNormal = [UIImage imageNamed:@"social-icon.png"];

[buttonSocial setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, 5.0)];
[buttonSocial setBackgroundImage:buttonBackgroundImagePressedLeft forState:UIControlStateHighlighted];
[buttonSocial setBackgroundImage:buttonBackgroundImagePressedLeft forState:UIControlStateSelected];
[buttonSocial setBackgroundImage:buttonBackgroundImagePressedLeft forState:(UIControlStateHighlighted|UIControlStateSelected)];
[buttonSocial setImage:buttonSocialImageNormal forState:UIControlStateNormal];
[buttonSocial setImage:buttonSocialImageNormal forState:UIControlStateSelected];
[buttonSocial setImage:buttonSocialImageNormal forState:UIControlStateHighlighted];
[buttonSocial setImage:buttonSocialImageNormal forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
// Button 2
UIButton *buttonStar = [[UIButton alloc] init];
UIImage *buttonStarImageNormal = [UIImage imageNamed:@"star-icon.png"];
    
[buttonStar setBackgroundImage:buttonBackgroundImagePressedCenter forState:UIControlStateHighlighted];
[buttonStar setBackgroundImage:buttonBackgroundImagePressedCenter forState:UIControlStateSelected];
[buttonStar setBackgroundImage:buttonBackgroundImagePressedCenter forState:(UIControlStateHighlighted|UIControlStateSelected)];
[buttonStar setImage:buttonStarImageNormal forState:UIControlStateNormal];
[buttonStar setImage:buttonStarImageNormal forState:UIControlStateSelected];
[buttonStar setImage:buttonStarImageNormal forState:UIControlStateHighlighted];
[buttonStar setImage:buttonStarImageNormal forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
// Button 3
UIButton *buttonSettings = [[UIButton alloc] init];
UIImage *buttonSettingsImageNormal = [UIImage imageNamed:@"settings-icon.png"];
    
[buttonSettings setBackgroundImage:buttonBackgroundImagePressedRight forState:UIControlStateHighlighted];
[buttonSettings setBackgroundImage:buttonBackgroundImagePressedRight forState:UIControlStateSelected];
[buttonSettings setBackgroundImage:buttonBackgroundImagePressedRight forState:(UIControlStateHighlighted|UIControlStateSelected)];
[buttonSettings setImage:buttonSettingsImageNormal forState:UIControlStateNormal];
[buttonSettings setImage:buttonSettingsImageNormal forState:UIControlStateSelected];
[buttonSettings setImage:buttonSettingsImageNormal forState:UIControlStateHighlighted];
[buttonSettings setImage:buttonSettingsImageNormal forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
// Setting the UIButtons used in the segmented control
[segmentedControl setButtonsArray:@[buttonSocial, buttonStar, buttonSettings]];

// Adding your control to the view
[viewController.view addSubview:segmentedControl];

This segmented control is a subclass of UIControl and you just need to add a target if you want to trigger a method:

// Adding a target
[segmentedControl addTarget:self action:@selector(segmentedControlTouched:) forControlEvents:UIControlEventValueChanged];

Check the example project for further details.

##Requirements

  • iOS >= 4.3
  • ARC

Contact

Ali Karagoz

License

AKASegmentedControl is available under the MIT license. See the LICENSE file for more info.

Comments
  • iOS 10: Class name taken by private frameworks

    iOS 10: Class name taken by private frameworks

    Just like it was pointed out in https://github.com/alikaragoz/AKSegmentedControl/issues/20, this library needs another name. It causes an exception in iOS10:

    -[AKSegmentedControl setSegmentedControlMode:]: unrecognized selector sent to instance...
    

    This is the log from the debugger when launching an app using this library:

    Class AKSegmentedControl is implemented in both /System/Library/PrivateFrameworks/AnnotationKit.framework/AnnotationKit (0x1b750c568) and /var/containers/Bundle/Application/A192D0FD-556C-4BB3-B910-AEAF2312DB39/... (0x100c9eb30).
    One of the two will be used. Which one is undefined.
    
    opened by dzenbot 8
  • How do I determine which button is pressed directly?

    How do I determine which button is pressed directly?

    AKSegmentedControl callback is NSIndexSet, How do I determine which button is pressed directly.Thanks

    • (void)segmentedViewController:(id)sender { AKSegmentedControl *segmentedControl = (AKSegmentedControl *)sender;

      if (segmentedControl == self.segmentedControl1) { //NSLog(@"SegmentedControl #1 ----: Selected Index %@", [segmentedControl selectedIndexes]); NSIndexSet *indexSet = [segmentedControl selectedIndexes]; NSLog(@"what index is kenpig %d", [indexSet containsIndex:0]); }

    opened by kenpig 7
  • Automatic resizing ?

    Automatic resizing ?

    Hey,

    i have two UIPopoverController with an AKSegmentControl in it. Both AKSegmentedControls are 140px width.

    One Popover is 320px width, the other ist 280px width. I set up the Control with the following Code: mehrfachAuswahl = [[AKSegmentedControl alloc] initWithFrame:CGRectMake((self.bounds.size.width - 20) - auswahlWidth, 7, auswahlWidth, 35.0)]; [mehrfachAuswahl addTarget:self action:@selector(segmentedViewController:) forControlEvents:UIControlEventValueChanged]; [mehrfachAuswahl setSegmentedControlMode:AKSegmentedControlModeMultipleSelectionable];

    Is it possible to deactive the autoresizing effekt?

    bildschirmfoto 2013-05-14 um 13 49 20 bildschirmfoto 2013-05-14 um 13 49 04

    The used UISegmentControl under the AKSegmentedControl is alwasy 140pc width.

    opened by ghost 3
  • Fixed sync issues leading to sometimes the separator not beeing shown

    Fixed sync issues leading to sometimes the separator not beeing shown

    Changed from using enumeratorWithBlock to using for/while in order to ensure sequential execution of building the view. It has been seen that when using enumeratorWithBlock, the separators are not always built correctly into the view

    opened by osunnarvik 1
  • Fix crash on iOS7 devices

    Fix crash on iOS7 devices

    On iOS7 devices, [NSArray enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:] will cause the block to run in background threads, and crashes. Remove the NSEnumerationConcurrent option fixes the crash.

    opened by leonskywalker 1
  • Clear the separator array when removing them from the superview.

    Clear the separator array when removing them from the superview.

    When calling rebuildSeparators, the separators are being removed from the view, but not the array. This is causing separatorsArray to append separatorsNumber objects that do not get placed into the view properly.

    opened by Benuuu 1
  • Fixing background image size when calling setFrame

    Fixing background image size when calling setFrame

    If you init the segmented control with CGRectZero then later resize the control, the background will get stuck with a height of zero and not display.

    eg:

    - (id)init
    {
        self = [super init];
        if (self) {
           _segmentedControl = [[AKSegmentedControl alloc] initWithFrame:CGRectZero];
        }
        return self;
    }
    

    ...

       [self.segmentedControl setFrame:(CGRect){10, 0, self.view.frame.size.width-20, 37}];
    

    Haven't seen any other issues introduced with this change but let me know if you think of something.

    opened by simonholroyd 1
  • When pressing the same button twice in a row in button mode, the button does nothing

    When pressing the same button twice in a row in button mode, the button does nothing

    When pressing the same button twice in a row in button mode, the button does nothing. It can be reset by pressing another button on the control, but this is not a good user experience.

    bug 
    opened by inPhilly 1
  • Call super's -layoutSubviews to make compatible with autolayout.

    Call super's -layoutSubviews to make compatible with autolayout.

    This fixes the following error when using autolayout:

    *** Terminating app due to uncaught exception ' NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. AKSegmentedControl's implementation of -layoutSubviews needs to call super.'

    opened by spaggetti 0
  • layoutSubviews needs to call super.

    layoutSubviews needs to call super.

    I have a crash 'Fatal Exception: NSInternalInconsistencyException Auto Layout still required after executing -layoutSubviews. AKSegmentedControl's implementation of -layoutSubviews needs to call super.' in iOS 7.

    fix it,

    opened by candyan 0
Releases(1.0.5)
Owner
Ali Karagoz
Wizard @mojo_video_app. Created @suplco. Ex @gopro / @quik_app / @zenlyapp
Ali Karagoz
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
A segmented control with custom appearance and interactive animations. Written in Swift 3.0.

SJFluidSegmentedControl About If you are bored with using the default UISegmentedControl, this might save your day. SJFluidSegmentedControl is a custo

Sasho Jadrovski 904 Dec 30, 2022
A Pinterest-like segment control with masking animation.

PinterestSegment A Pinterest-like segment control with masking animation. Requirements iOS 8.0+ Xcode 9.0 Swift 4.0 Installation CocoaPods You can use

TBXark 672 Dec 20, 2022
Runkeeper design switch control

DGRunkeeperSwitch Runkeeper design switch control (two part segment control) developed in Swift 2.0 Requirements Xcode 7-beta or higher iOS 8.0 or hig

Danil Gontovnik 1.9k Dec 2, 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
A highly customizable drop-in replacement for UISegmentedControl.

HMSegmentedControl A highly customizable drop-in replacement for UISegmentedControl, used by more than 22,000 apps, including TikTok, PayPal, Imgur an

Hesham Abd-Elmegid 3.9k Dec 21, 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
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
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
RCalendarPicker A date picker control, Calendar calendar control, select control, calendar, date selection, the clock selection control.

RCalendarPicker RCalendarPicker Calendar calendar control, select control, calendar, date selection, the clock selection control. 日历控件 ,日历选择控件,日历,日期选择

杜耀辉 131 Jul 18, 2022
A segmented control with custom appearance and interactive animations. Written in Swift 3.0.

SJFluidSegmentedControl About If you are bored with using the default UISegmentedControl, this might save your day. SJFluidSegmentedControl is a custo

Sasho Jadrovski 904 Dec 30, 2022
Animated top/bottom segmented control written in Swift.

Segmentio Animated top/bottom segmented control written in Swift. Check this project on dribbble. Requirements Xcode 10 iOS 8.x+ Swift 5.0 Installatio

Yalantis 2.4k Jan 9, 2023
Fully customizable pull-to-refresh control inspired by Storehouse iOS app

CBStoreHouseRefreshControl What is it? A fully customizable pull-to-refresh control for iOS inspired by Storehouse iOS app ![screenshot1] (https://s3.

Suyu Zhang 4k Jan 6, 2023
Fully customizable Facebook reactions like control

Reactions is a fully customizable control to give people more ways to share their reaction in a quick and easy way. Requirements • Usage • Installatio

Yannick Loriot 585 Dec 28, 2022
Custom segmented picker for SwiftUI

Custom segmented picker for SwiftUI

Sergey Kazakov 34 Dec 27, 2022
Easy to create & custom segmented view

TCSegmentedView Easy to create & custom segmented view Usage Examples An Objective-C example project demonstrating customization options is included i

Chuong Tran 22 Dec 4, 2022
Control Room : a macOS app that lets you control the simulators for iOS, tvOS, and watchOS

Control Room is a macOS app that lets you control the simulators for iOS, tvOS, and watchOS – their UI appearance, status bar configuration, and more.

null 0 Nov 30, 2021
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English 简体中文 What's a better way to know what PopMenu o

Cali Castle 1.5k Dec 30, 2022
A fully customizable library to easily display Animated Toast Messages in iOS using Swift!

CustomToastView-swift A fully customizable library to easily display Animated Toast Messages in iOS using Swift! Preview - All the custom toasts you c

Leticia Rodriguez 13 Aug 20, 2022
A fully customizable iOS Horizontal PickerView library, written in pure swift

ADDatePicker is Horizontal Date Picker Library written in Swift Requirements Communication Installation Usage Demo Customization Credits License Requi

Abhishek Dave 166 Dec 21, 2022