HMSegmentedControl 选项卡功能实现

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 and HMSegmentedControl.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.

HMSegmentedControl

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.

@HeshamMegid
http://hesh.am

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值