HMSegmentedControl
A drop-in replacement for UISegmentedControl mimicking the style of the segmented control used in Google Currents and various other Google products.
Features
- Supports both text and images
- Font and all colors are customizable
- Supports selection indicator both on top and bottom
- Supports blocks
- Works with ARC and iOS >= 5
Installation
CocoaPods
The easiest way of installing HMSegmentedControl is via CocoaPods.
pod 'HMSegmentedControl', '~> 1.1.0'
Cocoa-whaa?
If you haven't heard about CocoaPods (seriously, where were you?!), it's a dependency manager for Xcode projects that provides very simple installation of libraries. Here's how to get started.
Install CocoaPods if not already available:
$ [sudo] gem install cocoapods
$ pod setup
Change to the directory of your Xcode project, and Create and Edit your Podfile and add HMSegmentedControl:
$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
platform :ios, '5.0'
pod 'HMSegmentedControl', '~> 1.2.0'
Install into your project:
$ pod install
Open your project in Xcode from the .xcworkspace file (not the usual project file)
$ open MyProject.xcworkspace
Old-fashioned way
- Add
HMSegmentedControl.h
andHMSegmentedControl.m
to your project. - Add
QuartzCore.framework
to your linked frameworks. -
#import "HMSegmentedControl.h"
where you want to add the control.
Usage
The code below will create a segmented control with the default looks:
HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"One", @"Two", @"Three"]];
[segmentedControl setFrame:CGRectMake(10, 10, 300, 60)];
[segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];
Included is a demo project showing how to fully customise the control.
Change log
- v1.2.0
- Added new selection indicator style: HMSelectionIndicatorBox
- Added ability to set text colour for selected segment (thanks to @jmkr)
- Segment titles are now added in a separate CATextLayer, and images are drawn in a separate CALayer
- Calls to index change block/selector now happen before the animation starts
- Lots of code refactoring and clean up
- v1.1.0 (merged pull request from @jacksonpan)
- Added image support
- Support for changing selection indicator position
- v1.0.0
- Initial release
Apps using HMSegmentedControl
If you are using HMSegmentedControl in your app or know of an app that uses it, please add it to this list.
License
HMSegmentedControl is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
If this code was helpful, I would love to hear from you.
相关推荐
HMSegmentedControl ,HMSegmentedControl 是 UISegmentedControl 的替代品,模仿了 G...
公司项目需要,原先的HMSegmentedControl 不能响应点击相同的index,在原来的基础上增加了:- (void)setIndexSelectBlock:(IndexSelectBlock)indexSelectBlock;方法 来响应点击相同的index。
作者YUYINGJIE,源码YJPageController.git,结合HMSegmentedControl 选择器 与UIPageViewController 开发的一个demo
HMS分段控制 UISegmentedControl的高度可定制的替代产品,已被22,...用法下面的代码将创建具有默认外观的分段控件: let segmentedControl = HMSegmentedControl ( sectionTitles : [ " Trending " , " News " , " Li
仿网易左右滑动,有些自己的修改,修改了一些BUG
HM分段控制为 HMSegmentControl 添加底线和分隔线执照HMSegmentedControl 根据 MIT 许可条款获得许可。 有关完整详细信息,请参阅文件。 如果此代码有帮助,我很乐意听取您的意见。
源码HMSegmentedControl,源码HMSegmentedControl是UISegmentedControl的替代品,可以支持自定义 Segmented Control 的样式。在被选中的 segment 上加上颜色条。这种样式的 Segmented Control 比原有的 ...
基于HMSegmentedControl,写的一点小demo,仅供初学者参考,欢迎大家多提意见。
多页签显示,基于HMSegmentedControl再封装 git:https://github.com/1273011249/XYYSegmentControl 支持pod
结合HMSegmentedControl 选择器 与UIPageViewController 开发的一个demo GitHub:https://github.com/YUYINGJIE/YJPageController.git
最近有点空闲就自己写点东西,或者写出来的东西没什么水平,封装也不怎么好,但也算是一种分享,也想大神们指点一下。勿喷,有bug一起交流。里面用到了HMSegmentedControl,谢谢。
90%精仿原版有妖气漫画(登录,充值等涉及版权或会员等功能均不作实现) 在原版APP中加入自己的一些优化效果 在原版基础上适应全面屏 三方框架,感谢SnapKit,SnapKitExtend,然后是Moya,Alamofire,Ha
'HMSegmentedControl' pod 'MBProgressHUD' pod 'STPickerView' pod 'SDCycleScrollView' pod 'ZYCornerRadius', '~> 1.0.2' pod 'UITableView+FDTemplateLayoutCell' pod 'Masonry' pod 'RSKImageCropper'