Giter Site home page Giter Site logo

lkbadgeview's Introduction

Custom Badge View

LKBadgeView class draws text on round rect 'badge'.

*See japanese document

Installation

You should copy below files to your projects.

LKBadgeView.h LKBadgeView.m

Usage

LKBadgeView is subclass of UIView. So you can add the instance to some view.

LKBadgeView* badgeView =
	[[[LKBadgeView alloc] initWithFrame:CGRectMake(100, 200, 50, 20)] autorelease];
[self.view addSubview:badgeView];
badgeView.text = @"23";

You can use this class in XIB. The sample application use this way.

Customize

The below properties can customize the view's behaivior.

Horizontal position

@property (nonatomic, assign) LKBadgeViewHorizontalAlignment horizontalAlignment;

left/center/right alignments are available.
(Default) LKBadgeViewHorizontalAlignmentCenter

( The background color is convenient description )

Minimum size

Minimum size has 2 way mode.

@property (nonatomic, assign) LKBadgeViewWidthMode widthMode;

  • LKBadgeViewWidthModeSmall: The badge shape becomes circle.
  • LKBadgeViewWidthModeStandard: The width is certain fixed size in case of 1 char and 2 chars text. 3 chars and more.

(Default) LKBadgeViewWidthModeStandard

###Color Text color and badge color are variable.

@property (nonatomic, retain) UIColor* textColor;
@property (nonatomic, retain) UIColor* badgeColor;

(Default) textColor is white, badgeColor is gray.

###Outline LKBadgeView can use outline.

The outline property should be YES when you use outline. If the property is no, then the outline does not be drawn. Outline has color property and width property.

@property (nonatomic, retain) UIColor* outlineColor;
@property (nonatomic, assign) CGFloat outlineWidth;
@property (nonatomic, assign) BOOL outline;

(Default) outlineColor is gray, outlineWidth is 2.0.

You can use outline with badgeColor.

###Shadow LKBadgeView can draw a shadow.

If the shadow property is YES, then the shadow of the badge is drawn. 'shadowOfOutline' is for outline shadow. 'shadowOfText' is for text shadow.

@property (nonatomic, retain) BOOL shadow;
@property (nonatomic, assign) BOOL shadowOfOutline;
@property (nonatomic, assign) BOOL shadowOfText;

(Default) all shadow properties are NO.

Etc

Truncated

If text width is greater than LKBadgeView width, The text is truncated.

( The background color is convenient description )

Badge height

The height of badge shape is fixed (20px). The value is avaliable as constant. Also class method +badgeHeight is avalible.

#define LK_BADGE_VIEW_STANDARD_HEIGHT       20.0
  :
 + (CGFloat)badgeHeight;

LKBadgeView height should be same value or more. If LKBadgeView is greater than fixed size (20px), then the badge shape is placed at the center of vertical position in LKBadgeView. Usually the height of LKBadgeView itself is the same as the value and good

License

MIT

Copyright (c) 2011 Hiroshi Hashiguchi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lkbadgeview's People

Contributors

serahug avatar xcatsan avatar

Stargazers

 avatar

Watchers

 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.