使用HMSegmentedControl实现分段控件
2015-06-13 22:20
447 查看
如果文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额随意,重在心意^_^
我要捐赠: 点击捐赠
Cocos2d-X源码下载:点我传送
HMSegmentedControl 是 UISegmentedControl 的替代品,模仿了 Google Currents 使用的效果。
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 imagesFont 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 dependencymanager 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.hand
HMSegmentedControl.mto
your project.
Add
QuartzCore.frameworkto
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 *segmented = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"已收公告",@"已发公告"]];
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.
如果文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额随意,重在心意^_^
我要捐赠: 点击捐赠
Cocos2d-X源码下载:点我传送
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- flex 控件的重要属性
- Delphi控件ListView的属性及使用方法详解
- web下载的ActiveX控件自动更新
- WinForm实现按名称递归查找控件的方法
- C#中父窗口和子窗口之间控件互操作实例
- MFC中动态创建控件以及事件响应实现方法
- WinForm自定义函数FindControl实现按名称查找控件
- WinForm拖拽控件生成副本的解决方法
- ASP.NET的HtmlForm控件学习及Post与Get的区别概述
- WinForm实现移除控件某个事件的方法
- C#分屏控件用法实例
- jQuery操作表单常用控件方法小结
- C#的winform控件命名规范