GithubHelp home page GithubHelp logo

aotag's Introduction

#AOTag - simple tag implementation

AOTag is under MIT Licence so if you find it helpful just use it !

###AOTagDemo

This project add/remove tag with image and title inside a tag list view. When user tap on a tag, it's removed from the view. Please see the sample project for more.

The usage of distant tag image is supported by using EGOImageView module.

https://github.com/enormego/EGOImageLoading.git

###Screenshot: AOTagDemo in the iphone simulator

AOTagDemo in the simulator

##How To Use It

Sample project show a simple usage.

###Documentation

@protocol AOTagDelegate <NSObject>

@optional

// Delegate method to handle distant image loading

- (void)tagDistantImageDidLoad:(AOTag *)tag;
- (void)tagDistantImageDidFailLoad:(AOTag *)tag withError:(NSError *)error;

// Delegate method to handle tag action

- (void)tagDidAddTag:(AOTag *)tag;
- (void)tagDidRemoveTag:(AOTag *)tag;
- (void)tagDidSelectTag:(AOTag *)tag;

@end

/**
 * Define tag font name and font size.
 *
 * @param name the NSString font name. Default is @"Helvetica-Light".
 * @param size the NSString font size. Default is 12.0f.
 */
- (void)setTagFont:(NSString *)name withSize:(CGFloat)size;

/**************************
 * Methods to load tags with bundle images
 **************************/

/**
 * Create a new tag object
 *
 * @param tTitle the NSString tag label
 * @param tImage the NSString tag image named
 */
- (void)addTag:(NSString *)tTitle withImage:(NSString *)tImage;

/**
 * Create a new tag object with custom colors
 *
 * @param tTitle the NSString tag label
 * @param tImage the NSString tag image named
 * @param labelColor the UIColor tag label color. Default color is [UIColor whiteColor]
 * @param backgroundColor the UIColor tag background color. Default color is [UIColor colorWithRed:0.204 green:0.588 blue:0.855 alpha:1.000]
 * @param closeColor the UIColor tag close button color. Default color is [UIColor colorWithRed:0.710 green:0.867 blue:0.953 alpha:1.000]
 */
- (void)addTag:(NSString *)tTitle withImage:(NSString *)tImage withLabelColor:(UIColor *)labelColor withBackgroundColor:(UIColor *)backgroundColor withCloseButtonColor:(UIColor *)closeColor;

/**************************
 * Methods to load tags with distant images
 **************************/

/**
 * Create a new tag object
 *
 * @param tTitle the NSString tag label
 * @param imageURL the NSURL tag image
 * @param tPlaceholderImage the NSString tag image placeholder. If nil no image will be shown will downloading distant image
 */
- (void)addTag:(NSString *)tTitle withImageURL:(NSURL *)imageURL andImagePlaceholder:(NSString *)tPlaceholderImage;

/**
 * Create a new tag object with custom colors
 *
 * @param tTitle the NSString tag label
 * @param tPlaceholderImage the NSString tag image placeholder. If nil no image will be shown will downloading distant image
 * @param imageURL the NSURL tag image
 * @param labelColor the UIColor tag label color. Default color is [UIColor whiteColor]
 * @param backgroundColor the UIColor tag background color. Default color is [UIColor colorWithRed:0.204 green:0.588 blue:0.855 alpha:1.000]
 * @param closeColor the UIColor tag close button color. Default color is [UIColor colorWithRed:0.710 green:0.867 blue:0.953 alpha:1.000]
 */
- (void)addTag:(NSString *)tTitle withImagePlaceholder:(NSString *)tPlaceholderImage withImageURL:(NSURL *)imageURL withLabelColor:(UIColor *)labelColor withBackgroundColor:(UIColor *)backgroundColor withCloseButtonColor:(UIColor *)closeColor;

/**************************
 * Common methods for tags
 **************************/

/**
 * Create a new tags object and add them to the tag list view.
 *
 * @param tags the NSArray tag list to be added. The given tag must be of NSDictionary type (ie. @{@"title": @"Tyrion", @"image": @"tyrion.jpg"})
 */
- (void)addTags:(NSArray *)tags;

/**
 * Remove the given tag from the tag list view
 *
 * @param tag the AOTag instance to be removed
 */
- (void)removeTag:(AOTag *)tag;

/**
 * Remove all tags object
 */
- (void)removeAllTag;
    

###Code snippet

// First add the tag container view in your view controller

- (void)viewDidLoad
{
    [super viewDidLoad];
    
   self.tag = [[AOTagList alloc] initWithFrame:CGRectMake(0.0f,
                                                           50.0f,
                                                           320.0f,
                                                           300.0f)];
    
	// You can change tag font name and font size
    [self.tag setTagFont:@"Helvetica-Light" withSize:12.0f];

    [self.view addSubview:self.tag];

	// Then add new tag
	[self.tag addTag:@"my tag title" withImage:@"myTagImage.png"];
}
    
// Add tag with specific label, background and close button color
// If nil, custom color are used

- (void)viewDidLoad
{
    [super viewDidLoad];
    
   self.tag = [[AOTagList alloc] initWithFrame:CGRectMake(0.0f,
                                                           50.0f,
                                                           320.0f,
                                                           300.0f)];
    
	[self.view addSubview:self.tag];

	// Then add new tag
	[self.tag addTag:@"my tag title"
               withImage:[UIImage imageNamed:"myTagImage.png"]
          withLabelColor:[UIColor blackColor]
     withBackgroundColor:[UIColor redColor]
    withCloseButtonColor:[UIColor whiteColor]];
}
    
// Add tag with specific label, background and close button color with distant tag image and tag image placeholder
// If nil placeholder image, no image will be used as a placeholder
// If nil distant image URL, no image will be downloaded
// If nil custom color, built in colors are used

@see - (IBAction)addCustomColorTagWithDistantImage:(id)sender method in demo project

- (void)viewDidLoad
{
    [super viewDidLoad];
    
   self.tag = [[AOTagList alloc] initWithFrame:CGRectMake(0.0f,
                                                           50.0f,
                                                           320.0f,
                                                           300.0f)];
    
	[self.view addSubview:self.tag];

	// Then add new tag
    [self.tag addTag:@"my tag title"
               withImagePlaceholder:[UIImage imageNamed:"myTagImage.png"]
            withImageURL:[NSURL URLWithString:@"http://myTagDistantURL"]
          withLabelColor:[UIColor blackColor]
     withBackgroundColor:[colors objectAtIndex:arc4random() % [colors count]]
    withCloseButtonColor:[UIColor whiteColor]];
}
    
// Add tag with specific label, background and close button color with distant tag image and tag image placeholder
// If nil distant image URL, no image will be downloaded
// If nil custom color, built in colors are used

@see - (IBAction)addRandomTagWithDistantImage:(id)sender method in demo project

- (void)viewDidLoad
{
    [super viewDidLoad];
    
   self.tag = [[AOTagList alloc] initWithFrame:CGRectMake(0.0f,
                                                           50.0f,
                                                           320.0f,
                                                           300.0f)];
    
	[self.view addSubview:self.tag];

	// Then add new tag
    [self.tag addTag:@"my tag title" withImageURL:[NSURL URLWithString:@"http://myTagDistantURL"] andImagePlaceholder:[UIImage imageNamed:"myTagImage.png"]];
}
    

Any comments are welcomed

@Appsido [email protected]

aotag's People

Watchers

 avatar  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.