Skip to content

Instantly share code, notes, and snippets.

@dbrajkovic
Created April 11, 2012 21:07
Show Gist options
  • Save dbrajkovic/2362588 to your computer and use it in GitHub Desktop.
Save dbrajkovic/2362588 to your computer and use it in GitHub Desktop.
UIView Tag Categories
//
// UIView+TagExtensions.h
//
// Created by Daniel Brajkovic on 2/19/12.
#import <UIKit/UIKit.h>
@interface UIView (TagExtensions)
- (UIButton *)buttonWithTag:(NSInteger)aTag;
- (UIImageView *)imageViewWithTag:(NSInteger)aTag;
- (UILabel *)labelWithTag:(NSInteger)aTag;
- (UIScrollView *)scrollViewWithTag:(NSInteger)aTag;
- (UITextField *)textFieldWithTag:(NSInteger)aTag;
- (UITextView *)textViewWithTag:(NSInteger)aTag;
@end
//
// UIView+TagExtensions.m
//
// Created by Daniel Brajkovic on 2/19/12.
//
#import "UIView+TagExtensions.h"
@implementation UIView (TagExtensions)
- (UIButton *)buttonWithTag:(NSInteger)aTag
{
UIView *aView = [self viewWithTag:aTag];
if (aView && [aView isKindOfClass:[UIButton class]]) {
return (UIButton *) aView;
}
return nil;
}
- (UIImageView *)imageViewWithTag:(NSInteger)aTag
{
UIView *aView = [self viewWithTag:aTag];
if (aView && [aView isKindOfClass:[UIImageView class]]) {
return (UIImageView *) aView;
}
return nil;
}
- (UILabel *)labelWithTag:(NSInteger)aTag
{
UIView *aView = [self viewWithTag:aTag];
if (aView && [aView isKindOfClass:[UILabel class]]) {
return (UILabel *) aView;
}
return nil;
}
- (UIScrollView *)scrollViewWithTag:(NSInteger)aTag
{
UIView *aView = [self viewWithTag:aTag];
if (aView && [aView isKindOfClass:[UIScrollView class]]) {
return (UIScrollView *) aView;
}
return nil;
}
- (UITextField *)textFieldWithTag:(NSInteger)aTag
{
UIView *aView = [self viewWithTag:aTag];
if (aView && [aView isKindOfClass:[UITextField class]]) {
return (UITextField*) aView;
}
return nil;
}
- (UITextView *)textViewWithTag:(NSInteger)aTag
{
UIView *aView = [self viewWithTag:aTag];
if (aView && [aView isKindOfClass:[UITextView class]]) {
return (UITextView *) aView;
}
return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment