GithubHelp home page GithubHelp logo

zilaiyedaren / hthorizontalselectionlist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sinss/hthorizontalselectionlist

0.0 1.0 0.0 561 KB

A simple, horizontally-scrolling list of items that can be used as a more flexible replacement for UISegmentedControl

License: MIT License

Objective-C 87.08% Swift 4.71% Ruby 1.46% C 0.73% Shell 6.02%

hthorizontalselectionlist's Introduction

HTHorizontalSelectionList

A simple, horizontally-scrolling list of items that can be used as a more flexible replacement for UISegmentedControl

##Example

A simple side-scrolling list of items (perhaps filters for a UITableView below). alt tag

##Setup via CocoaPods

Add HTHorizontalSelectionList pod into your Podfile

pod 'HTHorizontalSelectionList', '~> 0.6.2'

##Usage ###Setup and Initialization

To begin using HTHorizontalSelectionList, import the main header:

#import <HTHorizontalSelectionList/HTHorizontalSelectionList.h>

The horizontal selection list uses a data-source/delegate model (similar to UITableView or UIPickerView). To setup a simple horizontal selection list, init the view and set it's delegate and data source:

@interface CarListViewController () <HTHorizontalSelectionListDataSource, HTHorizontalSelectionListDelegate>

@property (nonatomic, strong) HTHorizontalSelectionList *selectionList;
@property (nonatomic, strong) NSArray *carMakes;

@end

@implementation CarListViewController

- (void)viewDidLoad {
	[super viewDidLoad];

	self.selectionList = [[HTHorizontalSelectionList alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
	selectionList.delegate = self;
	selectionList.dataSource = self;

	self.carMakes = @[@"ALL CARS",
                      @"AUDI",
                      @"BITTER",
                      @"BMW",
                      @"BÜSSING",
                      @"GUMPERT",
                      @"MAN"];
}

#pragma mark - HTHorizontalSelectionListDataSource Protocol Methods

- (NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList {
    return self.carMakes.count;
}

- (NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index {
    return self.carMakes[index];
}

#pragma mark - HTHorizontalSelectionListDelegate Protocol Methods

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index {
    // update the view for the corresponding index
}

###Customizing the appearance

The HTHorizontalSelectionList has a number of configurable properties.

To adjust the font and color of the buttons use the following methods:

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
- (void)setTitleFont:(UIFont *)font forState:(UIControlState)state;

Default (unselected) state is configured with UIControlStateNormal. The selection list can be configured for three states: UIControlStateNormal, UIControlStateHightlighted and UIControlStateSelected. If no explicit colors or fonts are specified for the selected or highlighted states, the control will fallback on the normal style.

The appearance of the selection indicator can be configured with the following properties:

@property (nonatomic, strong) UIColor *selectionIndicatorColor;

@property (nonatomic) HTHorizontalSelectionIndicatorStyle selectionIndicatorStyle;

There are three selection styles:

typedef NS_ENUM(NSInteger, HTHorizontalSelectionIndicatorStyle) {
    HTHorizontalSelectionIndicatorStyleBottomBar,           // Default
    HTHorizontalSelectionIndicatorStyleButtonBorder,
    HTHorizontalSelectionIndicatorStyleNone
};

To configure the height of the bottom bar use:

@property (nonatomic) CGFloat selectionIndicatorHeight;

Default height is 3 points. To adjust how wide this bottom bar extends beyond the label use:

@property (nonatomic) CGFloat selectionIndicatorHorizontalPadding;

The default horizontal padding for the bottom bar is 7.5 points. These properties only take effect if selection style is HTHorizontalSelectionIndicatorStyleBottomBar.

The selection indicator bounce effect can be adjusted with this property:

@property (nonatomic) HTHorizontalSelectionIndicatorAnimationMode selectionIdicatorAnimationMode;

You can adjust the content insets of each button with:

@property (nonatomic) UIEdgeInsets buttonInsets;

Setting bottomTrimColor changes the appearance of the thin bottom border:

@property (nonatomic, strong) UIColor *bottomTrimColor;
@property (nonatomic) BOOL bottomTrimHidden;

hthorizontalselectionlist's People

Contributors

erikackermann avatar dustinburge avatar

Watchers

Kent avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.