mirror of
https://github.com/HackPlan/IQKeyboardManager.git
synced 2026-03-28 23:59:02 +08:00
Fixed Placeholder text position for IQTextView.
This commit is contained in:
@@ -22,14 +22,10 @@
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import "IQNSArray+Sort.h"
|
||||
#import "IQKeyboardManagerConstantsInternal.h"
|
||||
#import "IQUIView+Hierarchy.h"
|
||||
|
||||
#import <UIKit/UIView.h>
|
||||
|
||||
IQ_LoadCategory(IQNSArraySort)
|
||||
|
||||
|
||||
@implementation NSArray (IQ_NSArray_Sort)
|
||||
|
||||
- (NSArray*)sortedArrayByTag
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import "IQUIView+Hierarchy.h"
|
||||
#import "IQKeyboardManagerConstantsInternal.h"
|
||||
|
||||
#import <UIKit/UICollectionView.h>
|
||||
#import <UIKit/UITableView.h>
|
||||
@@ -34,10 +33,6 @@
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
|
||||
IQ_LoadCategory(IQUIViewHierarchy)
|
||||
|
||||
|
||||
@implementation UIView (IQ_UIView_Hierarchy)
|
||||
|
||||
//Special textFields,textViews,scrollViews
|
||||
|
||||
@@ -22,13 +22,8 @@
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import "IQUIWindow+Hierarchy.h"
|
||||
|
||||
#import <UIKit/UINavigationController.h>
|
||||
|
||||
#import "IQKeyboardManagerConstantsInternal.h"
|
||||
IQ_LoadCategory(IQUIWindowHierarchy)
|
||||
|
||||
|
||||
@implementation UIWindow (IQ_UIWindow_Hierarchy)
|
||||
|
||||
- (UIViewController*) topMostController
|
||||
|
||||
@@ -27,24 +27,19 @@
|
||||
//Xcode 4.6 or less compilation check
|
||||
#ifdef NSFoundationVersionNumber_iOS_6_1
|
||||
#define IQ_IS_IOS7_OR_GREATER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
|
||||
#define IQ_IS_XCODE_5_1_OR_GREATER 1
|
||||
#else
|
||||
#define IQ_IS_IOS7_OR_GREATER NO
|
||||
#define IQ_IS_XCODE_5_1_OR_GREATER 0
|
||||
#endif
|
||||
|
||||
//Xcode 5.1 or less compilation check
|
||||
#ifdef NSFoundationVersionNumber_iOS_7_1
|
||||
#define IQ_IS_IOS8_OR_GREATER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
|
||||
#define IQ_IS_XCODE_6_0_OR_GREATER 1
|
||||
#else
|
||||
#define IQ_IS_IOS8_OR_GREATER NO
|
||||
#define IQ_IS_XCODE_6_0_OR_GREATER 0
|
||||
#endif
|
||||
|
||||
|
||||
/** https://github.com/kif-framework/KIF/blob/master/Additions/LoadableCategory.h
|
||||
|
||||
@discussion To load categories in the current file loadable without using "-load-all" flag. When we try to create framework or library the compilers skips linking files that contain only categories. So use this macro to add a dummy class, which causes the linker to add the file. You will also need to add "-ObjC" to the "Other Linker Flags" build setting in any project that uses the framework.
|
||||
|
||||
@param UNIQUE_NAME A globally unique name.
|
||||
*/
|
||||
#define IQ_LoadCategory(UNIQUE_NAME) @interface FORCELOAD_##UNIQUE_NAME :NSObject @end @implementation FORCELOAD_##UNIQUE_NAME @end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#import "IQTextView.h"
|
||||
|
||||
#import <UIKit/UILabel.h>
|
||||
#import <UIKit/UINibLoading.h>
|
||||
|
||||
@implementation IQTextView
|
||||
{
|
||||
@@ -32,6 +33,31 @@
|
||||
|
||||
@synthesize placeholder = _placeholder;
|
||||
|
||||
-(void)initialize
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshPlaceholder) name:UITextViewTextDidChangeNotification object:self];
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self initialize];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)awakeFromNib
|
||||
{
|
||||
[super awakeFromNib];
|
||||
[self initialize];
|
||||
}
|
||||
|
||||
-(void)refreshPlaceholder
|
||||
{
|
||||
if([[self text] length])
|
||||
@@ -42,18 +68,26 @@
|
||||
{
|
||||
[placeHolderLabel setAlpha:1];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setText:(NSString *)text
|
||||
{
|
||||
[super setText:text];
|
||||
[self refreshPlaceholder];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
-(void)setFont:(UIFont *)font
|
||||
{
|
||||
[super setFont:font];
|
||||
placeHolderLabel.font = self.font;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
-(void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
[placeHolderLabel sizeToFit];
|
||||
placeHolderLabel.frame = CGRectMake(8, 8, CGRectGetWidth(self.frame)-16, CGRectGetHeight(placeHolderLabel.frame));
|
||||
}
|
||||
|
||||
-(void)setPlaceholder:(NSString *)placeholder
|
||||
@@ -62,7 +96,7 @@
|
||||
|
||||
if ( placeHolderLabel == nil )
|
||||
{
|
||||
placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectInset(self.bounds, 8, 8)];
|
||||
placeHolderLabel = [[UILabel alloc] init];
|
||||
placeHolderLabel.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
|
||||
placeHolderLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
placeHolderLabel.numberOfLines = 0;
|
||||
@@ -77,11 +111,4 @@
|
||||
[self refreshPlaceholder];
|
||||
}
|
||||
|
||||
//When any text changes on textField, the delegate getter is called. At this time we refresh the textView's placeholder
|
||||
-(id<UITextViewDelegate>)delegate
|
||||
{
|
||||
[self refreshPlaceholder];
|
||||
return [super delegate];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
#import <UIKit/UILabel.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
IQ_LoadCategory(IQUIViewToolbar)
|
||||
|
||||
/*UIKeyboardToolbar Category implementation*/
|
||||
@implementation UIView (IQToolbarAddition)
|
||||
|
||||
@@ -442,6 +440,9 @@ IQ_LoadCategory(IQUIViewToolbar)
|
||||
UIImage *imageLeftArrow;
|
||||
UIImage *imageRightArrow;
|
||||
|
||||
//Xcode Compilation check
|
||||
#if IQ_IS_XCODE_6_0_OR_GREATER
|
||||
|
||||
if (IQ_IS_IOS8_OR_GREATER)
|
||||
{
|
||||
// Get the top level "bundle" which may actually be the framework
|
||||
@@ -458,6 +459,7 @@ IQ_LoadCategory(IQUIViewToolbar)
|
||||
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
imageLeftArrow = [UIImage imageNamed:@"IQKeyboardManager.bundle/IQButtonBarArrowLeft"];
|
||||
imageRightArrow = [UIImage imageNamed:@"IQKeyboardManager.bundle/IQButtonBarArrowRight"];
|
||||
@@ -564,6 +566,9 @@ IQ_LoadCategory(IQUIViewToolbar)
|
||||
UIImage *imageLeftArrow;
|
||||
UIImage *imageRightArrow;
|
||||
|
||||
//Xcode Compilation check
|
||||
#if IQ_IS_XCODE_6_0_OR_GREATER
|
||||
|
||||
if (IQ_IS_IOS8_OR_GREATER)
|
||||
{
|
||||
// Get the top level "bundle" which may actually be the framework
|
||||
@@ -580,6 +585,7 @@ IQ_LoadCategory(IQUIViewToolbar)
|
||||
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
imageLeftArrow = [UIImage imageNamed:@"IQKeyboardManager.bundle/IQButtonBarArrowLeft"];
|
||||
imageRightArrow = [UIImage imageNamed:@"IQKeyboardManager.bundle/IQButtonBarArrowRight"];
|
||||
|
||||
BIN
KeyboardTextFieldDemo/.DS_Store
vendored
BIN
KeyboardTextFieldDemo/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
@@ -13,5 +13,21 @@
|
||||
stopOnStyle = "0">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "../IQKeyBoardManager/IQTextView/IQTextView.m"
|
||||
timestampString = "449693144.569059"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "90"
|
||||
endingLineNumber = "90"
|
||||
landmarkName = "-layoutSubviews"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
Reference in New Issue
Block a user