• This repository has been archived on 12/Jul/2019
  • Stars
    star
    384
  • Rank 111,726 (Top 3 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 12 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍫 Fully customizable Segmented Control for iOS

#AKASegmentedControl

AKASegmentedControl is a fully customizable Segmented Control for iOS

##Preview preview

##Usage

Installation

CocoaPods

You can use CocoaPods to install AKASegmentedControl by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'AKASegmentedControl'

To get the full benefits import AKASegmentedControl.h wherever you import UIKit

#import "AKASegmentedControl.h"

Manually

  1. Download and drop /AKASegmentedControl folder in your project.
  2. Congratulations!

Usage

// Initialization of the segmented control
AKASegmentedControl *segmentedControl = [[AKASegmentedControl alloc] initWithFrame:aRect]
[segmentedControl addTarget:self action:@selector(segmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];

// Setting the resizable background image
UIImage *backgroundImage = [[UIImage imageNamed:@"segmented-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
[segmentedControl setBackgroundImage:backgroundImage];

// Setting the content edge insets to adapte to you design
[segmentedControl setContentEdgeInsets:UIEdgeInsetsMake(2.0, 2.0, 3.0, 2.0)];

// Setting the behavior mode of the control
[segmentedControl setSegmentedControlMode:AKASegmentedControlModeSticky];

// Setting the separator image
[segmentedControl setSeparatorImage:[UIImage imageNamed:@"segmented-separator.png"]];

UIImage *buttonBackgroundImagePressedLeft = [[UIImage imageNamed:@"segmented-bg-pressed-left.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 4.0, 0.0, 1.0)];
UIImage *buttonBackgroundImagePressedCenter = [[UIImage imageNamed:@"segmented-bg-pressed-center.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 4.0, 0.0, 1.0)];
UIImage *buttonBackgroundImagePressedRight = [[UIImage imageNamed:@"segmented-bg-pressed-right.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 1.0, 0.0, 4.0)];

// Button 1
UIButton *buttonSocial = [[UIButton alloc] init];
UIImage *buttonSocialImageNormal = [UIImage imageNamed:@"social-icon.png"];

[buttonSocial setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, 5.0)];
[buttonSocial setBackgroundImage:buttonBackgroundImagePressedLeft forState:UIControlStateHighlighted];
[buttonSocial setBackgroundImage:buttonBackgroundImagePressedLeft forState:UIControlStateSelected];
[buttonSocial setBackgroundImage:buttonBackgroundImagePressedLeft forState:(UIControlStateHighlighted|UIControlStateSelected)];
[buttonSocial setImage:buttonSocialImageNormal forState:UIControlStateNormal];
[buttonSocial setImage:buttonSocialImageNormal forState:UIControlStateSelected];
[buttonSocial setImage:buttonSocialImageNormal forState:UIControlStateHighlighted];
[buttonSocial setImage:buttonSocialImageNormal forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
// Button 2
UIButton *buttonStar = [[UIButton alloc] init];
UIImage *buttonStarImageNormal = [UIImage imageNamed:@"star-icon.png"];
    
[buttonStar setBackgroundImage:buttonBackgroundImagePressedCenter forState:UIControlStateHighlighted];
[buttonStar setBackgroundImage:buttonBackgroundImagePressedCenter forState:UIControlStateSelected];
[buttonStar setBackgroundImage:buttonBackgroundImagePressedCenter forState:(UIControlStateHighlighted|UIControlStateSelected)];
[buttonStar setImage:buttonStarImageNormal forState:UIControlStateNormal];
[buttonStar setImage:buttonStarImageNormal forState:UIControlStateSelected];
[buttonStar setImage:buttonStarImageNormal forState:UIControlStateHighlighted];
[buttonStar setImage:buttonStarImageNormal forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
// Button 3
UIButton *buttonSettings = [[UIButton alloc] init];
UIImage *buttonSettingsImageNormal = [UIImage imageNamed:@"settings-icon.png"];
    
[buttonSettings setBackgroundImage:buttonBackgroundImagePressedRight forState:UIControlStateHighlighted];
[buttonSettings setBackgroundImage:buttonBackgroundImagePressedRight forState:UIControlStateSelected];
[buttonSettings setBackgroundImage:buttonBackgroundImagePressedRight forState:(UIControlStateHighlighted|UIControlStateSelected)];
[buttonSettings setImage:buttonSettingsImageNormal forState:UIControlStateNormal];
[buttonSettings setImage:buttonSettingsImageNormal forState:UIControlStateSelected];
[buttonSettings setImage:buttonSettingsImageNormal forState:UIControlStateHighlighted];
[buttonSettings setImage:buttonSettingsImageNormal forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
// Setting the UIButtons used in the segmented control
[segmentedControl setButtonsArray:@[buttonSocial, buttonStar, buttonSettings]];

// Adding your control to the view
[viewController.view addSubview:segmentedControl];

This segmented control is a subclass of UIControl and you just need to add a target if you want to trigger a method:

// Adding a target
[segmentedControl addTarget:self action:@selector(segmentedControlTouched:) forControlEvents:UIControlEventValueChanged];

Check the example project for further details.

##Requirements

  • iOS >= 4.3
  • ARC

Contact

Ali Karagoz

License

AKASegmentedControl is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

MCSwipeTableViewCell

👆 Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).
Objective-C
2,955
star
2

AIDatePickerController

📅 UIDatePicker modally presented with iOS 7 custom transitions.
Objective-C
90
star
3

Swifty-News

📰 Simple app built with Swift
Swift
46
star
4

DaisyChain

🔗 Easy animation chaining
Swift
30
star
5

Flickr-Search

Simple iOS app which consumes the Flickr Search API
Objective-C
23
star
6

AKCircleMaskTransitionController

Custom view controller transition using a circular mask
Objective-C
15
star
7

Relative-Time-Update

A simple demo project showing how to implement the automatic time update in a UITableViewCells
Objective-C
15
star
8

figma-xcode-app-icon-exporter

This plugin automatically generates a zipped AppIcon.appiconset container from a selected frame in Figma
TypeScript
9
star
9

alfred-extensions

Alfred 2 workflows and themes
6
star
10

SUPL-iOS-App

This repository contains the client code of the now retired SUPL iOS app
Swift
3
star
11

Keolocation

Simple iOS application which partially consumes the Keolis API
Objective-C
2
star
12

alikaragoz.net

Photography website of Ali Karagoz
Ruby
2
star
13

alikaragoz

1
star
14

krgz.me

HTML
1
star
15

.dotfiles

1
star
16

xcode-spm-github-action-fastlane-test

HTML
1
star
17

SwiftTouchDemo

(WWDC #235) Advanced Scrollviews and Touch Handling Techniques
Swift
1
star
18

FreeLib

HTML5 Velib' mobile client for iOS
JavaScript
1
star
19

UsingARenderPipelineToRenderPrimitives

Objective-C
1
star
20

dotfiles

Ruby
1
star
21

Social-Sharing-iOS-7

Demo project to show sharing issue when the URL is shortened itunes link
Objective-C
1
star