SMSegment
SMSegment supports setting up tabs with pictures using web pictures and local pictures.
Features
- Supports multiple style,including style of text, image and both text and image.
- Supports display net images with 'URL'.
- Supports advanced title styling with text attributes for font and color.
- Support horizontal scrolling and scroll to center.
- Supports blocks to observe index changed.
- Works with ARC and iOS >= 8.
Installation
CocoaPods
The easiest way of installing SMSegment is via CocoaPods.
pod 'SMSegment'
Old-fashioned way
- Add
resourle
file to your project. #import "SMSegment.h"
where you want to add the control.
Usage
You can create 'SMSegment' instance by instance functions and class functions.
NSArray *titles = @[@"One", @"Two", @"Three", @"Four", @"Five",@"Six", @"Seven", @"Eight", @"Nine", @"Ten"];
NSString *urlString = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1529668872575&di=c1f145e6c728b8bb145e8d2a10193155&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F0196a156c937e46ac7252ce68a8504.png";
NSArray *images = @[@"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal", @"sc_normal"];
NSArray *selectedImages = @[@"urlString", @"sc_selected", @"sc_selected", @"sc_selected", @"sc_selected", @"sc_selected", @"sc_selected", @"urlString", @"sc_selected", @"sc_selected"];
SMSegment *textSegment = [[SMSegment alloc] initWithTitles:titles];
SMSegment *imageSegment = [[SMSegment alloc] initWithImages:images selectedImages:selectedImages];
SMSegment *textImageSegment = [[SMSegment alloc] initWithImages:images selectedImages:selectedImages titles:titles];
or
SMSegment *textSegment = [SMSegment segmentWithTitles:titles];
SMSegment *imageSegment = [SMSegment segmentWithImages:images selectedImages:selectedImages];
SMSegment *textImageSegment = [SMSegment segmentWithImages:images selectedImages:selectedImages titles:titles];
You can observe index by block like this:
segment.indexChangeBlock = ^(NSInteger index) {
NSLog(@"to do something");
};
You can also set segment properties to change seagment appearence.If you want to know all usages,please check the 'viewController.m' file in the project.
Attention
- Don't create instance with system init functions,because SMSegment forbids those functions.
- Please make sure of the number of the images and the number of the selected images are the same when the segment type is 'SMSegmentTypeImage'.
- Please make sure of the number of the titles, images and selected images are same when the segment type is 'SMSegmentTypeTextImage'.
License
SMSegment is licensed under the terms of the MIT License. Please see the LICENSE file for full details.