Home

Awesome

YUSegment

Pod Version Carthage compatible Pod Platform Pod License

中文文档

A customizable segmented control for iOS.

YUSegment-demo

Features

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]];
<br/>
- (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];
<br/>

Properties

 return the number of segments in a segmented control.

 If assign it to 32.0.

padding-32

License

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