Skip to content

Instantly share code, notes, and snippets.

@ryancole
Created August 14, 2012 02:27
Show Gist options
  • Save ryancole/3345817 to your computer and use it in GitHub Desktop.
Save ryancole/3345817 to your computer and use it in GitHub Desktop.
A subclass of `UITextField` that has a prefixed label.
//
// TitleField.h
// mustached-bear
//
// Created by Ryan Cole on 8/12/12.
// Copyright (c) 2012 Ryan Cole. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TitleField : UITextField
@end
//
// TitleField.m
// mustached-bear
//
// Created by Ryan Cole on 8/12/12.
// Copyright (c) 2012 Ryan Cole. All rights reserved.
//
#import "TitleField.h"
@implementation TitleField
- (void)awakeFromNib {
// init the padding view
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 20)];
labelView.text = @"Title: ";
labelView.textAlignment = UITextAlignmentRight;
labelView.textColor = [UIColor colorWithWhite:0 alpha:0.6];
// set the padding view
self.leftView = labelView;
self.leftViewMode = UITextFieldViewModeAlways;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment