A customizable Segmented Control for iOS. Supports text and image.

Overview

YUSegment

Pod Version Carthage compatible Pod Platform Pod License

中文文档

A customizable segmented control for iOS.

YUSegment-demo

Features

  • 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

Installation

Cocoapods

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

Carthage

github "afishhhhh/YUSegment"

Usage

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.

APIs

Methods

- (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;

example:

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

- (void)setTextAttributes:(nullable NSDictionary *)attributes 
                 forState:(YUSegmentedControlState)state;

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.

example:

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

Properties

  • 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.

    padding-0

 If assign it to 32.0.

padding-32

  • 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];

License

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

You might also like...
Customizable segmented control with interactive animation.
Customizable segmented control with interactive animation.

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

RCalendarPicker A date picker control, Calendar calendar control, select control, calendar, date selection, the clock selection control.
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. 日历控件 ,日历选择控件,日历,日期选择

A segmented control with custom appearance and interactive animations. Written in Swift 3.0.
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

Animated top/bottom segmented control written in Swift.
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

Custom segmented picker for SwiftUI
Custom segmented picker for SwiftUI

Custom segmented picker for SwiftUI

Easy to create & custom segmented view
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

add text(multiple line support) to imageView, edit, rotate or resize them as you want, then render the text on image
add text(multiple line support) to imageView, edit, rotate or resize them as you want, then render the text on image

StickerTextView is an subclass of UIImageView. You can add multiple text to it, edit, rotate, resize the text as you want with one finger, then render the text on Image.

Detecting Text in Natural Image with Connectionist Text Proposal Network (ECCV'16)

Detecting Text in Natural Image with Connectionist Text Proposal Network The codes are used for implementing CTPN for scene text detection, described

A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

🌍⏩📄 Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.

ISO8859 Convert ISO8859 1-16 Encoded Text to String in Swift. Usage let encoding = ISO8859.part1 let string = String([...], iso8859Encoding: encoding)

UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.
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

UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.
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

A text view that supports selection and expansion
A text view that supports selection and expansion

The Problem UILabel and UITextView offer unsatisfying support for text selection. Existing solutions like TTTAttributedLabel are great but offer a som

This library for animating text. Developed with SwiftUI. This library supports iOS/macOS.

AnimateText This library for animating text. Developed with SwiftUI. This library supports iOS/macOS. Screenshot AnimateText.mp4 Example https://fabul

Lightweight and customisable async image loading in SwiftUI. Supports on-disk storage, placeholders and more!
Lightweight and customisable async image loading in SwiftUI. Supports on-disk storage, placeholders and more!

Asyncrounously download and display images in Swift UI. Supports progress indicators, placeholders and image transitions. RemoteImageView Asyncrounous

A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types
A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types

A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types

ScrollView that supports a parallax header image and static overlay.

ScrollViewReactiveHeader A replacement ScrollView that provides a header with subtle scroll animations. example-video.mov Using ScrollViewReactiveHead

DGImageView - Asynchronous image downloader with cache. Supports gif too

DGImageView Installation Usage DGImageView Asynchronous image downloader with cache. Supports gif, memory cache, disk cache features. Installation Xco

Control Room : a macOS app that lets you control the simulators for iOS, tvOS, and watchOS
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.

Comments
  • Provide height customization for vertical seperator

    Provide height customization for vertical seperator

    If you can provide this this libabry will be very usefull with all kind of customization And also if you can provide color property for vertical and bottom seperator

    opened by poonamdhomane 0
  • 点快了,indicator跑偏掉了,还有选中的状态没有变化,帮你修复了下

    点快了,indicator跑偏掉了,还有选中的状态没有变化,帮你修复了下

    simulator screen shot 2017 5 24 7 53 41 simulator screen shot 2017 5 24 7 53 46 simulator screen shot 2017 5 24 7 53 53

    贴上修复方式,供你参考,如果说有更好的方式,渴望有你的不同见解

    - (void)segmentDidSelectAtIndex:(NSUInteger)newIndex didDeselectAtIndex:(NSUInteger)oldIndex {

    // update UI
    if (_contentType == YUSegmentedControlContentTypeText) {
        
        for (Item *item in _items) {
            NSInteger index = [_items indexOfObject:item];
            UILabel *deselectedLabel = (UILabel *)(item.view);
            deselectedLabel.attributedText = [[NSAttributedString alloc] initWithString:_contents[index] attributes:_attributesNormal];
        }
        
        UILabel *selectedLabel = (UILabel *)(_items[newIndex].view);
        selectedLabel.attributedText = [[NSAttributedString alloc] initWithString:_contents[newIndex] attributes:_attributesSelected];
    

    // UILabel *deselectedLabel = (UILabel *)(_items[oldIndex].view); // deselectedLabel.attributedText = [[NSAttributedString alloc] initWithString:_contents[oldIndex] attributes:_attributesNormal]; } else { if (_selectedImages) { UIImageView *selectedImageView = (UIImageView *)(_items[newIndex].view); selectedImageView.image = _selectedImages[newIndex]; UIImageView *deselectedImageView = (UIImageView *)(_items[oldIndex].view); deselectedImageView.image = _contents[oldIndex]; } } // animation [self moveIndicatorFromIndex:oldIndex toIndex:newIndex]; }

    • (void)moveIndicatorFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {

    // CABasicAnimation *animation; // CGPoint position = _indicator.position; // CGFloat position_x = position.x + CGRectGetWidth(_indicator.bounds) * (toIndex - fromIndex); // position.x = position_x; // // if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) { // animation = [CASpringAnimation animationWithKeyPath:@"position.x"]; // } else { // animation = [CABasicAnimation animationWithKeyPath:@"position.x"]; // } // animation.toValue = [NSValue valueWithCGPoint:position]; // animation.duration = 0.25;

    // indicator animate
    CGRect frame = _indicator.frame;
    frame.origin.x = CGRectGetWidth(_indicator.bounds) * toIndex ;
    NSLog(@"%f",frame.origin.x);
    [UIView animateWithDuration:kAnimationDuration
                          delay:0.0
         usingSpringWithDamping:0.66
          initialSpringVelocity:3.0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
                         _indicator.frame = frame;
        
    } completion:^(BOOL finished) {
        if (finished) {
            _selectedSegmentIndex = toIndex;
            [self sendActionsForControlEvents:UIControlEventValueChanged];
        }
    }];
    

    }

    opened by HCat 0
Releases(1.0.1)
Owner
YyGgQq
前端菜鸡,日常写 bug
YyGgQq
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
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
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
A segment switcher with dynamic text mask effect

DynamicMaskSegmentSwitch A segment switcher with dynamic text mask effect ##Preview: Indicator will bounce when progress less than 0 or larger than 1.

Qitao Yang 309 Oct 7, 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
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