diff --git a/Demo/Default-568h@2x.png b/Demo/Default-568h@2x.png new file mode 100644 index 0000000..0891b7a Binary files /dev/null and b/Demo/Default-568h@2x.png differ diff --git a/Demo/GCPlaceholderTextViewDemo.xcodeproj/project.pbxproj b/Demo/GCPlaceholderTextViewDemo.xcodeproj/project.pbxproj index 70881cf..695201c 100644 --- a/Demo/GCPlaceholderTextViewDemo.xcodeproj/project.pbxproj +++ b/Demo/GCPlaceholderTextViewDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 622CC0C9193C91B5001E9172 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 622CC0C8193C91B5001E9172 /* Default-568h@2x.png */; }; B0B559FA1361DFFA00A8E980 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B0B559F91361DFFA00A8E980 /* UIKit.framework */; }; B0B559FC1361DFFA00A8E980 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B0B559FB1361DFFA00A8E980 /* Foundation.framework */; }; B0B559FE1361DFFA00A8E980 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B0B559FD1361DFFA00A8E980 /* CoreGraphics.framework */; }; @@ -20,6 +21,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 622CC0C8193C91B5001E9172 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "../Default-568h@2x.png"; sourceTree = ""; }; B0B559F51361DFFA00A8E980 /* GCPlaceholderTextViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCPlaceholderTextViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; B0B559F91361DFFA00A8E980 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; B0B559FB1361DFFA00A8E980 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -97,6 +99,7 @@ isa = PBXGroup; children = ( B0B55A0B1361DFFA00A8E980 /* MainWindow.xib */, + 622CC0C8193C91B5001E9172 /* Default-568h@2x.png */, B0B55A011361DFFA00A8E980 /* GCPlaceholderTextViewDemo-Info.plist */, B0B55A021361DFFA00A8E980 /* InfoPlist.strings */, B0B55A051361DFFA00A8E980 /* GCPlaceholderTextViewDemo-Prefix.pch */, @@ -141,7 +144,7 @@ B0B559EC1361DFFA00A8E980 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0510; ORGANIZATIONNAME = LittleKiwi; }; buildConfigurationList = B0B559EF1361DFFA00A8E980 /* Build configuration list for PBXProject "GCPlaceholderTextViewDemo" */; @@ -167,6 +170,7 @@ buildActionMask = 2147483647; files = ( B0B55A041361DFFA00A8E980 /* InfoPlist.strings in Resources */, + 622CC0C9193C91B5001E9172 /* Default-568h@2x.png in Resources */, B0B55A0D1361DFFA00A8E980 /* MainWindow.xib in Resources */, B0B55A131361DFFA00A8E980 /* GCPlaceholderTextViewDemoViewController.xib in Resources */, ); @@ -219,7 +223,6 @@ B0B55A141361DFFA00A8E980 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; @@ -228,7 +231,8 @@ GCC_VERSION = com.apple.compilers.llvmgcc42; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 4.3; + IPHONEOS_DEPLOYMENT_TARGET = 5.1.1; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; @@ -236,13 +240,12 @@ B0B55A151361DFFA00A8E980 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvmgcc42; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 4.3; + IPHONEOS_DEPLOYMENT_TARGET = 5.1.1; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; }; @@ -259,6 +262,7 @@ GCC_PREFIX_HEADER = "GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemo-Prefix.pch"; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = "GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemo-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.1.1; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -274,6 +278,7 @@ GCC_PREFIX_HEADER = "GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemo-Prefix.pch"; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = "GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemo-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.1.1; PRODUCT_NAME = "$(TARGET_NAME)"; VALIDATE_PRODUCT = YES; WRAPPER_EXTENSION = app; diff --git a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.h b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.h index 6d056ce..d2975c7 100644 --- a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.h +++ b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.h @@ -12,7 +12,7 @@ @interface GCPlaceholderTextViewDemoAppDelegate : NSObject -@property (nonatomic, strong) IBOutlet UIWindow *window; -@property (nonatomic, strong) IBOutlet GCPlaceholderTextViewDemoViewController *viewController; +@property (nonatomic, strong) UIWindow *window; +@property (nonatomic, strong) GCPlaceholderTextViewDemoViewController *viewController; @end diff --git a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.m b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.m index 6b57a8a..2d34410 100644 --- a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.m +++ b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoAppDelegate.m @@ -12,14 +12,10 @@ @implementation GCPlaceholderTextViewDemoAppDelegate -@synthesize window=_window; -@synthesize viewController=_viewController; - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window.rootViewController = self.viewController; - [self.window makeKeyAndVisible]; - return YES; + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + return YES; } - @end diff --git a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.h b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.h index 78b6fca..7120a33 100644 --- a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.h +++ b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.h @@ -9,9 +9,9 @@ #import #import "GCPlaceholderTextView.h" -@interface GCPlaceholderTextViewDemoViewController : UIViewController +@interface GCPlaceholderTextViewDemoViewController : UIViewController -@property (nonatomic, strong) IBOutlet GCPlaceholderTextView *textView; +@property (nonatomic, weak) IBOutlet GCPlaceholderTextView *textView; - (IBAction)finish:(id)sender; - (IBAction)refreshText:(id)sender; diff --git a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.m b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.m index bb03477..dc57810 100644 --- a/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.m +++ b/Demo/GCPlaceholderTextViewDemo/GCPlaceholderTextViewDemoViewController.m @@ -10,28 +10,19 @@ @implementation GCPlaceholderTextViewDemoViewController -@synthesize textView; - - (void)viewDidLoad { - [super viewDidLoad]; - - self.textView.placeholderColor = [UIColor redColor]; - self.textView.placeholder = NSLocalizedString(@"This is a placeholder",); + [super viewDidLoad]; + + self.textView.placeholderColor = UIColor.redColor; + self.textView.placeholder = NSLocalizedString(@"This is a placeholder",); } - (IBAction)finish:(id)sender { - [self.textView resignFirstResponder]; + [self.textView resignFirstResponder]; } - (IBAction)refreshText:(id)sender { - [self.textView setText:@""]; -} - - -- (void)viewDidUnload -{ - [self setTextView:nil]; - [super viewDidUnload]; + self.textView.text = @""; } @end diff --git a/Demo/GCPlaceholderTextViewDemo/en.lproj/GCPlaceholderTextViewDemoViewController.xib b/Demo/GCPlaceholderTextViewDemo/en.lproj/GCPlaceholderTextViewDemoViewController.xib index 6939ab4..0c04ce6 100644 --- a/Demo/GCPlaceholderTextViewDemo/en.lproj/GCPlaceholderTextViewDemoViewController.xib +++ b/Demo/GCPlaceholderTextViewDemo/en.lproj/GCPlaceholderTextViewDemoViewController.xib @@ -1,277 +1,51 @@ - - - - 1552 - 12D78 - 3084 - 1187.37 - 626.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 2083 - - - YES - IBProxyObject - IBUIBarButtonItem - IBUINavigationBar - IBUINavigationItem - IBUITextView - IBUIView - - - YES - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - YES - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - YES - - - 274 - {{0, 44}, {320, 416}} - - - 1 - MSAxIDEAA - - YES - YES - IBCocoaTouchFramework - - - 2 - IBCocoaTouchFramework - - - Helvetica - Helvetica - 0 - 17 - - - Helvetica - 17 - 16 - - - - - 290 - {320, 44} - - IBCocoaTouchFramework - - YES - - - Demo - - IBCocoaTouchFramework - 1 - - 16 - - - IBCocoaTouchFramework - 1 - - 0 - - IBCocoaTouchFramework - - - - - {{0, 20}, {320, 460}} - - - - 3 - MC43NQA - - 2 - - - NO - - IBCocoaTouchFramework - - - - - YES - - - view - - - - 7 - - - - textView - - - - 10 - - - - finish: - - - - 15 - - - - refreshText: - - - - 17 - - - - - YES - - 0 - - YES - - - - - - -1 - - - File's Owner - - - -2 - - - - - 6 - - - YES - - - - - - - 8 - - - - - 11 - - - YES - - - - - - 13 - - - YES - - - - - - - 14 - - - - - 16 - - - - - - - YES - - YES - -1.CustomClassName - -1.IBPluginDependency - -2.CustomClassName - -2.IBPluginDependency - 11.IBPluginDependency - 13.IBPluginDependency - 14.IBPluginDependency - 16.IBPluginDependency - 6.IBPluginDependency - 8.CustomClassName - 8.IBPluginDependency - - - YES - GCPlaceholderTextViewDemoViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - GCPlaceholderTextView - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - YES - - - - - - YES - - - - - 17 - - - 0 - IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 - - - YES - 3 - 2083 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/GCPlaceholderTextViewDemo/main.m b/Demo/GCPlaceholderTextViewDemo/main.m index 8e35500..4c6af58 100644 --- a/Demo/GCPlaceholderTextViewDemo/main.m +++ b/Demo/GCPlaceholderTextViewDemo/main.m @@ -8,10 +8,9 @@ #import -int main(int argc, char *argv[]) -{ - @autoreleasepool { - int retVal = UIApplicationMain(argc, argv, nil, nil); - return retVal; - } +int main(int argc, char *argv[]){ + @autoreleasepool { + int retVal = UIApplicationMain(argc, argv, nil, nil); + return retVal; + } } diff --git a/GCPlaceholderTextView.podspec b/GCPlaceholderTextView.podspec new file mode 100644 index 0000000..1c6f9c3 --- /dev/null +++ b/GCPlaceholderTextView.podspec @@ -0,0 +1,12 @@ +Pod::Spec.new do |s| + s.name = "GCPlaceholderTextView" + s.version = "1.0.1" + s.summary = "A subclass of UITextView that allow a placeholder." + s.homepage = "http://gcamp.ca/" + s.license = { :type => 'MIT', :file => 'LICENSE.txt' } + s.author = { "Guillaume Campagna" => "http://gcamp.ca/" } + s.source = { :git => "git@github.com:gcamp/GCPlaceholderTextView.git", :tag => s.version.to_s } + s.platform = :ios, '5.1.1' + s.source_files = 'GCPlaceholderTextView/*.{h,m}' + s.requires_arc = true +end diff --git a/GCPlaceholderTextView/GCPlaceholderTextView.h b/GCPlaceholderTextView/GCPlaceholderTextView.h index c548034..81d6c96 100644 --- a/GCPlaceholderTextView/GCPlaceholderTextView.h +++ b/GCPlaceholderTextView/GCPlaceholderTextView.h @@ -8,8 +8,7 @@ #import - -@interface GCPlaceholderTextView : UITextView +@interface GCPlaceholderTextView : UITextView @property(nonatomic, strong) NSString *placeholder; diff --git a/GCPlaceholderTextView/GCPlaceholderTextView.m b/GCPlaceholderTextView/GCPlaceholderTextView.m index 69d6483..654ec02 100644 --- a/GCPlaceholderTextView/GCPlaceholderTextView.m +++ b/GCPlaceholderTextView/GCPlaceholderTextView.m @@ -8,122 +8,129 @@ #import "GCPlaceholderTextView.h" -@interface GCPlaceholderTextView () +@interface GCPlaceholderTextView () -@property (unsafe_unretained, nonatomic, readonly) NSString* realText; +@property (weak, nonatomic, readonly) NSString *realText; -- (void) beginEditing:(NSNotification*) notification; -- (void) endEditing:(NSNotification*) notification; +- (void)beginEditing:(NSNotification *)notification; +- (void)endEditing:(NSNotification *)notification; @end @implementation GCPlaceholderTextView -@synthesize realTextColor; -@synthesize placeholder; -@synthesize placeholderColor; +#pragma mark +#pragma mark - Initialization -#pragma mark - -#pragma mark Initialisation +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; -- (id) initWithFrame:(CGRect)frame { - if ((self = [super initWithFrame:frame])) { - [self awakeFromNib]; - } - return self; + _placeholder = nil; + _placeholderColor = nil; + _realTextColor = nil; } -- (void)awakeFromNib { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginEditing:) name:UITextViewTextDidBeginEditingNotification object:self]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endEditing:) name:UITextViewTextDidEndEditingNotification object:self]; - - self.realTextColor = self.textColor; - self.placeholderColor = [UIColor lightGrayColor]; +- (id)initWithFrame:(CGRect)frame { + if ((self = [super initWithFrame:frame])) { + [self setup]; + } + return self; } -#pragma mark - -#pragma mark Setter/Getters - -- (void) setPlaceholder:(NSString *)aPlaceholder { - if ([self.realText isEqualToString:placeholder] && ![self isFirstResponder]) { - self.text = aPlaceholder; - } - if (aPlaceholder != placeholder) { - placeholder = aPlaceholder; - } - - - [self endEditing:nil]; +- (id)initWithCoder:(NSCoder *)aDecoder { + if ((self = [super initWithCoder:aDecoder])) { + [self setup]; + } + return self; } -- (void)setPlaceholderColor:(UIColor *)aPlaceholderColor { - placeholderColor = aPlaceholderColor; - - if ([super.text isEqualToString:self.placeholder]) { - self.textColor = self.placeholderColor; - } +- (void)setup { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginEditing:) name:UITextViewTextDidBeginEditingNotification object:self]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endEditing:) name:UITextViewTextDidEndEditingNotification object:self]; + + self.realTextColor = self.textColor; + self.placeholderColor = ((self.realTextColor == nil) ? [UIColor colorWithWhite:0.0 alpha:0.3] : [self.realTextColor colorWithAlphaComponent:0.3]); } -- (NSString *) text { - NSString* text = [super text]; - if ([text isEqualToString:self.placeholder]) return @""; - return text; +#pragma mark +#pragma mark - Setter/Getters + +- (void)setPlaceholder:(NSString *)aPlaceholder { + if ([self.realText isEqualToString:_placeholder] && ![self isFirstResponder]) { + self.text = aPlaceholder; + } + if (aPlaceholder != _placeholder) { + _placeholder = aPlaceholder; + } + + [self endEditing:nil]; } -- (void) setText:(NSString *)text { - if (([text isEqualToString:@""] || text == nil) && ![self isFirstResponder]) { - super.text = self.placeholder; - } - else { - super.text = text; - } - - if ([text isEqualToString:self.placeholder] || text == nil) { - self.textColor = self.placeholderColor; - } - else { - self.textColor = self.realTextColor; - } +- (void)setPlaceholderColor:(UIColor *)aPlaceholderColor { + _placeholderColor = aPlaceholderColor; + + if ([super.text isEqualToString:self.placeholder]) { + self.textColor = self.placeholderColor; + } } -- (NSString *) realText { - return [super text]; +- (NSString *)text { + if ([self.realText isEqualToString:self.placeholder] && [self.textColor isEqual:self.placeholderColor]) { + return @""; + } + return self.realText; } -- (void) beginEditing:(NSNotification*) notification { - if ([self.realText isEqualToString:self.placeholder]) { - super.text = nil; - self.textColor = self.realTextColor; - } +- (void)setText:(NSString *)text { + if (([text isEqualToString:@""] || text == nil) && ![self isFirstResponder]) { + super.text = self.placeholder; + } + else if ([text isEqualToString:self.placeholder]) { + return; + } + else { + super.text = text; + } + + if ([super.text isEqualToString:self.placeholder] || super.text == nil) { + self.textColor = self.placeholderColor; + } + else { + self.textColor = self.realTextColor; + } } -- (void) endEditing:(NSNotification*) notification { - if ([self.realText isEqualToString:@""] || self.realText == nil) { - super.text = self.placeholder; - self.textColor = self.placeholderColor; - } +- (NSString *)realText { + return super.text; } -- (void) setTextColor:(UIColor *)textColor { - if ([self.realText isEqualToString:self.placeholder]) { - if ([textColor isEqual:self.placeholderColor]){ - [super setTextColor:textColor]; - } else { - self.realTextColor = textColor; - } - } - else { - self.realTextColor = textColor; - [super setTextColor:textColor]; - } +- (void)beginEditing:(NSNotification *)notification { + if ([self.realText isEqualToString:self.placeholder] && [self.textColor isEqual:self.placeholderColor]) { + super.text = nil; + self.textColor = self.realTextColor; + } } -#pragma mark - -#pragma mark Dealloc +- (void)endEditing:(NSNotification *)notification { + if ([self.realText isEqualToString:@""] || self.realText == nil) { + super.text = self.placeholder; + self.textColor = self.placeholderColor; + } +} -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - +- (void)setTextColor:(UIColor *)textColor { + if ([self.realText isEqualToString:self.placeholder]) { + if ([textColor isEqual:self.placeholderColor]) { + super.textColor = textColor; + } + else { + self.realTextColor = textColor; + } + } + else { + self.realTextColor = textColor; + super.textColor = textColor; + } } @end diff --git a/GCPlaceholderTextView/GCPlaceholderTextView.m.orig b/GCPlaceholderTextView/GCPlaceholderTextView.m.orig new file mode 100644 index 0000000..8b91c5c --- /dev/null +++ b/GCPlaceholderTextView/GCPlaceholderTextView.m.orig @@ -0,0 +1,136 @@ +// +// GCPlaceholderTextView.m +// GCLibrary +// +// Created by Guillaume Campagna on 10-11-16. +// Copyright 2010 LittleKiwi. All rights reserved. +// + +#import "GCPlaceholderTextView.h" + +@interface GCPlaceholderTextView () + +@property (weak, nonatomic, readonly) NSString *realText; + +- (void)beginEditing:(NSNotification *)notification; +- (void)endEditing:(NSNotification *)notification; + +@end + +@implementation GCPlaceholderTextView + +#pragma mark +#pragma mark - Initialization + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + _placeholder = nil; + _placeholderColor = nil; + _realTextColor = nil; +} + +- (id)initWithFrame:(CGRect)frame { + if ((self = [super initWithFrame:frame])) { + [self setup]; + } + return self; +} + +- (void)awakeFromNib { + [super awakeFromNib]; + [self setup]; +} + +- (void)setup { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginEditing:) name:UITextViewTextDidBeginEditingNotification object:self]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endEditing:) name:UITextViewTextDidEndEditingNotification object:self]; + + self.realTextColor = self.textColor; + self.placeholderColor = [UIColor lightGrayColor]; +} + +#pragma mark +#pragma mark - Setter/Getters + +- (void)setPlaceholder:(NSString *)aPlaceholder { + if ([self.realText isEqualToString:_placeholder] && ![self isFirstResponder]) { + self.text = aPlaceholder; + } + if (aPlaceholder != _placeholder) { + _placeholder = aPlaceholder; + } + + [self endEditing:nil]; +} + +- (void)setPlaceholderColor:(UIColor *)aPlaceholderColor { + _placeholderColor = aPlaceholderColor; + + if ([super.text isEqualToString:self.placeholder]) { + self.textColor = self.placeholderColor; + } +} + +- (NSString *)text { + NSString *text = super.text; + if ([text isEqualToString:self.placeholder]) { + return @""; + }; + return text; +} + +- (void)setText:(NSString *)text { + if (([text isEqualToString:@""] || text == nil) && ![self isFirstResponder]) { + super.text = self.placeholder; + } + else { + super.text = text; + } + +<<<<<<< HEAD + if ([super.text isEqualToString:self.placeholder] || super.text == nil) { +======= + if ([super.text isEqualToString:self.placeholder] || text == nil) { +>>>>>>> origin/master + self.textColor = self.placeholderColor; + } + else { + self.textColor = self.realTextColor; + } +} + +- (NSString *)realText { + return super.text; +} + +- (void)beginEditing:(NSNotification *)notification { + if ([self.realText isEqualToString:self.placeholder]) { + super.text = nil; + self.textColor = self.realTextColor; + } +} + +- (void)endEditing:(NSNotification *)notification { + if ([self.realText isEqualToString:@""] || self.realText == nil) { + super.text = self.placeholder; + self.textColor = self.placeholderColor; + } +} + +- (void)setTextColor:(UIColor *)textColor { + if ([self.realText isEqualToString:self.placeholder]) { + if ([textColor isEqual:self.placeholderColor]) { + super.textColor = textColor; + } + else { + self.realTextColor = textColor; + } + } + else { + self.realTextColor = textColor; + super.textColor = textColor; + } +} + +@end