Giter VIP home page Giter VIP logo

mesegmentedcontrol's Introduction

Introduction

MESegmentedControl is an enhanced UISegmentedControl which allows you to set badge numbers on each of the control's segments, like so:

First Screnshot

Installation

  1. Copy the following files from the MESegmentedControl directory into your project. Link them to your target.
    1. MESegmentedControl.h
    2. MESegmentedControl.m
    3. CustomBadge.h
    4. CustomBadge.m
  2. MESegmentedControl should use ARC but CustomBadge should not. So if your project does use ARC, set the compiler flag -fno-objc-arc for the CustomBadge.m source within your target. If your project doesn't use ARC, set the compiler flag -fobjc-arc for the MESegmentedControl.m source within your target. See illustrated instructions here.

Usage

  1. Within your application, replace instances of UISegmentedControl with MESegmentedControl.
  2. Set badge numbers using, e.g. [segmentedControl setBadgeNumber:1 forSegmentAtIndex:0]. Set a badge number to 0 to remove the badge. Assign custom colours to badges using blocks - see MEViewController.m.
  3. Consider setting your badge numbers in your view controller's viewWillAppear method and clearing them using [segmentedControl clearBadges] in viewDidDisappear.
  4. MESegmentedControl should not be placed directly on a UINavigationItem due to issues during push / pop transitions. If you wish to use MESegmentedControl within a UINavigationItem (as in the screenshot above), then do not do so directly. Instead, place a transparent UIView onto the UINavigationItem and place the MESegmentedControl onto the transparent UIView.
  5. If you need to add or remove segments after adding your first badge, then call [segmentedControl clearBadges] beforehand. It's not sufficient here to simply set your badges to zero.
  6. To get the current badge number of a segment, call NSUInteger i=[segmentedControl getBadgeNumberForSegmentAtIndex:0].

Open the included XCode project to see a sample app.

Limitations

  • Segments must each be the same size.
  • Badges can only take positive integer values.

Neither of these limitations are inherent to the platform: they may be resolved with straightforward enhancements to the library.

License

MESegmentedControl is distributed under the Modified BSD License.

Credits

  • MESegmentedControl was written by Dave Thompson.
  • The CustomBadge component was written by Sascha Paulus. See Sascha's blog.

mesegmentedcontrol's People

Watchers

Stefan Klumpp avatar mako avatar  avatar Javier Chávarri avatar José González avatar Alexander Bunkenburg avatar James Cloos avatar Jordi Giménez Gámez avatar Paolo Tagliani avatar Aleix Ventayol avatar Joan Martin avatar Pol Batlló avatar Luciano Santana avatar Jose Luis Franconetti avatar Marc Torruella avatar Stefano Driussi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.