Shimen the main contribution, respect the work of the author, please do not reprint.
If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate the amount at random, ^_^
I want to donate: Click Donate
Cocos2d-x source Download: Dot I teleport
Hmsegmentedcontrol is an alternative to uisegmentedcontrol, mimicking the effect Google currents uses.
Hmsegmentedcontrol
A drop-in replacement for Uisegmentedcontrol mimicking the style of the segmented control used in Google currents and Vari ous other Google products.
Features
- Supports both text and images
- Font and all colors is customizable
- Supports selection indicator both on top and bottom
- Supports blocks
- Works with ARC and IOS >= 5
installationCocoaPods
The easiest-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 Prov Ides very simple installation of libraries. Here's how to get started.
Install CocoaPods if not already available:
[sudo] gem install cocoapodspod 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 Podfileplatform: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
- Add and to
HMSegmentedControl.h
HMSegmentedControl.m
your project.
- Add to
QuartzCore.framework
your linked frameworks.
#import "HMSegmentedControl.h"
Where you want to add the control.
Usage
The code below would create a segmented control with the default looks:
Hmsegmentedcontrol *segmented = [[Hmsegmentedcontrol alloc] initwithsectiontitles:@[@ "received notice", @ "posted notice"]; Segmented.autoresizingmask = Uiviewautoresizingflexiblerightmargin | Uiviewautoresizingflexiblewidth; Segmented.frame = CGRectMake (self.view.bounds.size.width/2-100, 4, 200, 40); Segmented.backgroundcolor = [Uicolor Clearcolor]; Segmented.selectionindicatorheight = 3.0f; Segmented.font = [Uifont fontwithname:@ "Stheitisc-light" size:19.0f]; Segmented.textcolor = Whrgb (255, 175, 185); Segmented.selectedtextcolor = [Uicolor Whitecolor]; Segmented.selectionindicatorcolor = [Uicolor Whitecolor]; Segmented.selectionstyle = Hmsegmentedcontrolselectionstylefullwidthstripe; Segmented.selectionindicatorlocation = Hmsegmentedcontrolselectionindicatorlocationdown; [Segmented addtarget:self action: @selector (Segmentedcontrolchangedvalue:) forControlEvents: Uicontroleventvaluechanged]; Self.segmentedcontrol = segmented; [Self.navigationController.navigationBAr addsubview:segmented];
Included is a demo project showing how to fully customise the control.
Shimen the main contribution, respect the work of the author, please do not reprint.
If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate the amount at random, ^_^
I want to donate: Click Donate
Cocos2d-x source Download: Dot I teleport
Implementing a segmented control using Hmsegmentedcontrol