Implementing a segmented control using Hmsegmentedcontrol

Source: Internet
Author: User
Tags install cocoapods

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.