| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723 |
- //
- // CustomInsetTextField.m
- // JasonDevelop
- //
- // Created by Jason Lee on 2013. 12. 6..
- // Copyright (c) jasondevelop. All rights reserved.
- //
- #import "NSString-Addtions.h"
- #import "CommonUtil.h"
- #import "CustomTextField.h"
- #import "ImageUtil.h"
- #define kUIBtnTintColor [UIColor whiteColor]
- #define kfBoxCap 12.0f
- #define kUIPlaceHolderColor RGBCOLOR(136, 143, 168)
- @interface CustomTextField () <UIKeyInput> {
- @protected
- UIView *_targetSuperView;
- CGRect _cRect;
- CGRect _superRect;
- CGPoint _contentOffset;
- CGFloat _marginTop, _naviMargin, _adjustY;
- UIBarButtonItem *_btnPrev, *_btnNext, *_btnClose;
- UIToolbar *_toolBar;
- NSMutableArray *_barItems;
- UIBarButtonItem *_btnFlexibleSpace;
- UIEdgeInsets _bgInsets;
- BOOL _isSecureEntry;
- BOOL _isScrollUp;
- }
- @end
- CGRect gKeyboardRect;
- @implementation CustomTextField
- @dynamic delegate;
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- _customTextFieldSuperview = _customTextFieldSuperview == CustomTextFieldSuperviewIsNone ? CustomTextFieldSuperviewIsViewController : _customTextFieldSuperview;
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- _bgImageName = @"img_input_round_bg_default";
- UIImage *bgImage = [UIImage imageNamed:_bgImageName];
- if (bgImage) {
- _bgInsets = UIEdgeInsetsMake(kfBoxCap, kfBoxCap, kfBoxCap, kfBoxCap);
- bgImage = [ImageUtil resizableImageWithCapInsets:_bgInsets resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- if (self.placeholder) {
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName:kUIPlaceHolderColor}];
- self.attributedPlaceholder = attrString;
- }
- _cRect = self.frame;
- }
- return self;
- }
- - (id)initWithFrame:(CGRect)frame bgImageName:(NSString *)btnImageName bgPressImageName:(NSString *)bgPressImageName {
- if (self = [super initWithFrame:frame]) {
- _customTextFieldSuperview = _customTextFieldSuperview == CustomTextFieldSuperviewIsNone ? CustomTextFieldSuperviewIsViewController : _customTextFieldSuperview;
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- _bgPressImageName = bgPressImageName;
- UIImage *bgImage = _bgImageName && ![_bgImageName isEmptyString] ? [UIImage imageNamed:_bgImageName] : [UIImage imageNamed:@"input_wh"];
- if (bgImage) {
- bgImage = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(kfBoxCap, kfBoxCap, kfBoxCap, kfBoxCap) resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- if (self.placeholder) {
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName:kUIPlaceHolderColor}];
- self.attributedPlaceholder = attrString;
- }
- _cRect = self.frame;
- }
- return self;
- }
- - (id)initWithFrame:(CGRect)frame hasMoveButton:(BOOL)hasMoveButton disablePrev:(BOOL)disablePrev disableNext:(BOOL)disableNext {
- if (self = [super initWithFrame:frame]) {
- _customTextFieldSuperview = _customTextFieldSuperview == CustomTextFieldSuperviewIsNone ? CustomTextFieldSuperviewIsViewController : _customTextFieldSuperview;
- _hasMoveButton = hasMoveButton;
- _disablePrevButton = disablePrev;
- _disableNextButton = disableNext;
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- _bgImageName = @"img_input_round_bg_default";
- UIImage *bgImage = [UIImage imageNamed:_bgImageName];
- if (bgImage) {
- _bgInsets = UIEdgeInsetsMake(kfBoxCap, kfBoxCap, kfBoxCap, kfBoxCap);
- bgImage = [ImageUtil resizableImageWithCapInsets:_bgInsets resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- if (self.placeholder) {
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName:kUIPlaceHolderColor}];
- self.attributedPlaceholder = attrString;
- }
- _cRect = self.frame;
- }
- return self;
- }
- - (void)awakeFromNib {
- _customTextFieldSuperview = _customTextFieldSuperview == CustomTextFieldSuperviewIsNone ? CustomTextFieldSuperviewIsViewController : _customTextFieldSuperview;
- self.inputAccessoryView = [self generateAccessoryView];
- // self.borderStyle = UITextBorderStyleNone;
- _bgImageName = _bgImageName && ![_bgImageName isEmptyString] ? _bgImageName : @"img_input_round_bg_default";
- _bgDisableImageName = _bgDisableImageName && ![_bgDisableImageName isEmptyString] ? _bgDisableImageName : @"img_input_round_bg_disable";
- UIImage *bgImage = [UIImage imageNamed:_bgImageName];
- if (bgImage) {
- if (!CGRectEqualToRect(_rectForCapBackground, CGRectZero)) {//rectForCap이 설정된 경우, 이미지를 리사이즈함.
- CGFloat top, left, bottom, right;
- top = CGRectGetMinY(_rectForCapBackground);
- left = CGRectGetMinX(_rectForCapBackground);
- bottom = CGRectGetHeight(_rectForCapBackground);
- right = CGRectGetWidth(_rectForCapBackground);
- _bgInsets = UIEdgeInsetsMake(top, left, bottom, right);
- } else {
- _bgInsets = UIEdgeInsetsMake(kfBoxCap, kfBoxCap, kfBoxCap, kfBoxCap);
- }
- bgImage = [ImageUtil resizableImageWithCapInsets:_bgInsets resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- if (self.placeholder) {
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName:kUIPlaceHolderColor}];
- self.attributedPlaceholder = attrString;
- }
- _cRect = self.frame;
- if (self.secureTextEntry) {
- _isSecureEntry = self.secureTextEntry;
- }
- #ifdef DEBUG
- NSString *identifier = [NSString stringWithFormat:@"%@", self.placeholder];
- [self setValue:identifier forKey:@"layoutDebuggingIdentifier"];
- #endif
- }
- - (UIView *)generateAccessoryView {
- self.keyboardAppearance = UIKeyboardAppearanceDark;
- CGFloat width = [UIScreen mainScreen].bounds.size.width;
- _toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, width, 44.0)];
- _toolBar.barStyle = UIBarStyleBlack;
- _toolBar.translucent = YES;
- _barItems = [NSMutableArray new];
- _btnFlexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
- _btnPrev = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"이전", @"이전")
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(goPrevField:)];
- _btnNext = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"다음", @"다음")
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(goNextField:)];
- _btnClose = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"닫기", @"닫기")
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(hideKeyboard:)];
- if (IOS_VERSION >= 7.0f) {
- _btnClose.tintColor = kUIBtnTintColor;
- _btnPrev.tintColor = kUIBtnTintColor;
- _btnNext.tintColor = kUIBtnTintColor;
- }
- if (_hasMoveButton) {
- [_barItems addObject:_btnPrev];
- [_barItems addObject:_btnNext];
- _btnPrev.enabled = !_disablePrevButton;
- _btnNext.enabled = !_disableNextButton;
- }
- [_barItems addObject:_btnFlexibleSpace];
- [_barItems addObject:_btnClose];
- [_toolBar setItems:_barItems animated:YES];
- return _toolBar;
- }
- - (void)setCustomTextFieldSuperview:(CustomTextFieldSuperview)customTextFieldSuperview {
- if (!_autoScrollUp) {
- return;
- }
- _customTextFieldSuperview = customTextFieldSuperview;
- if (_customTextFieldSuperview == CustomTextFieldSuperviewIsViewController) {
- UIViewController *vc = [CommonUtil currentViewController];
- vc = vc.presentedViewController ? vc.presentedViewController : vc;
- _targetSuperView = vc.view;
- } else if (_customTextFieldSuperview == CustomTextFieldSuperviewIsPopup) {
- _targetSuperView = self.superview.superview;
- _adjustY = 130.0f;
- } else if (_customTextFieldSuperview == CustomTextFieldSuperviewIsPopupContentView) {
- _targetSuperView = self.superview.superview.superview; //팝업에서의 viewInRect로 계산됨.
- } else if (_customTextFieldSuperview == CustomTextFieldSuperviewIsScrollView) {
- _targetSuperView = self.superview;
- if ([_targetSuperView isKindOfClass:[UIScrollView class]]) {
- UIScrollView *sv = (UIScrollView *)_targetSuperView;
- _contentOffset = sv.contentOffset;
- _naviMargin = 150.0f;
- _adjustY = 0.0f; //?
- }
- } else if (_customTextFieldSuperview == CustomTextFieldSuperviewIsContentView) {
- _targetSuperView = self.superview.superview.superview.superview;
- // _targetSuperView = self.superview;
- if ([_targetSuperView isKindOfClass:[UIScrollView class]]) {
- UIScrollView *sv = (UIScrollView *)_targetSuperView;
- _contentOffset = sv.contentOffset;
- _naviMargin = 80.0f;
- _adjustY = 0.0f; //?
- }
- } else if (_customTextFieldSuperview == CustomTextFieldSuperviewIsChildViewController) {
- UIViewController *cvc = [CommonUtil currentViewController];
- _targetSuperView = cvc.view;
- // if ([_targetSuperView isKindOfClass:[UIScrollView class]]) {
- // UIScrollView *sv = (UIScrollView *)_targetSuperView;
- // _contentOffset = sv.contentOffset;
- // _naviMargin = 0.0f;
- // _adjustY = 0.0f; //?
- // }
- }
- }
- - (void)scrollUp {
- if (_autoScrollUp) {
- if (CGRectEqualToRect(CGRectZero, gKeyboardRect)) {
- [self performSelector:@selector(scrollUp) withObject:nil afterDelay:0.1f];
- return;
- }
- if (!_targetSuperView) {
- [self setCustomTextFieldSuperview:_customTextFieldSuperview];
- }
-
- CGRect selfRect = self.frame;
- if (CGRectEqualToRect(_superRect, CGRectZero)) {//기존 위치를 저장함.
- _superRect = _targetSuperView.frame;
- }
- CGRect cr = [self.superview convertRect:selfRect toView:_targetSuperView];
- if (_customTextFieldSuperview == CustomTextFieldSuperviewIsPopupContentView || _customTextFieldSuperview == CustomTextFieldSuperviewIsChildViewController) {
- cr = [self.superview convertRect:selfRect toView:[[UIApplication sharedApplication].delegate window]];
- }
- CGFloat cy = CGRectGetMaxY(cr) + _adjustY;
- CGFloat ay = gKeyboardRect.size.height + 60;//(gKeyboardRect.size.height + KEYBOARD_ACCESSORY_HEIGHT + KEYBOARD_PREDICTS_HEIGHT);
- CGFloat ky = ([UIScreen mainScreen].bounds.size.height - _naviMargin) - ay; // 260
- NSLog(@"_superRect1 %@, cy=%f", NSStringFromCGRect(_superRect), cy);
- if (cy >= ky) {
- __block CGRect scrollRect = _targetSuperView.frame;
- scrollRect.origin.y = ky - cy;
- [UIView animateWithDuration:kfAnimationDur animations:^{
- if ([_targetSuperView isKindOfClass:[UIScrollView class]]) {
- CGFloat offsetY = _contentOffset.y + (cy - ky);
- [(UIScrollView *)_targetSuperView setContentOffset:CGPointMake(0, offsetY) animated:NO];
- } else {
- if (_customTextFieldSuperview == CustomTextFieldSuperviewIsPopupContentView || _customTextFieldSuperview == CustomTextFieldSuperviewIsChildViewController) {
- scrollRect.origin.y += _superRect.origin.y;
- }
- _targetSuperView.frame = scrollRect;
- }
- } completion:^(BOOL finished) {
- _isScrollUp = YES;
- }];
- } else {
- if (!CGRectEqualToRect(_superRect, CGRectZero)) {
- [UIView animateWithDuration:kfAnimationDur animations:^{
- _targetSuperView.frame = _superRect;
- } completion:^(BOOL finished) {
- _isScrollUp = YES;
- }];
- }
- }
- }
- }
- - (BOOL)becomeFirstResponder {
-
- _bgPressImageName = _bgPressImageName && ![_bgPressImageName isEmptyString] ? _bgPressImageName : @"img_input_round_bg_active";
- UIImage *bgImage = [UIImage imageNamed:_bgPressImageName];
- if (bgImage) {
- bgImage = [ImageUtil resizableImageWithCapInsets:_bgInsets resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
-
- if ([self isKindOfClass:[CustomSearchTextField class]] || _isScrollUp) {
- return [super becomeFirstResponder];
- }
-
- //텍스트필드가 여러개일 경우, 다른 텍스트필드에서 resign을 처리하기 전에 호출되는 문제를 해결함.
- for (id textField in _targetSuperView.subviews) {
- if ([textField isKindOfClass:[UITextField class]] && [textField isFirstResponder]) {
- [textField resignFirstResponder];
- NSLog(@"regisgn t=%@, s=%@", textField, self);
- }
- }
-
- _isScrollUp = NO;
-
- [self scrollUp];
- return [super becomeFirstResponder];
- }
- - (BOOL)resignFirstResponder {
-
- UIImage *bgImage = [UIImage imageNamed:_bgImageName];
- bgImage = [ImageUtil resizableImageWithCapInsets:_bgInsets resizingMode:UIImageResizingModeStretch img:bgImage];
-
- [self setBackground:bgImage];
- if ([self isKindOfClass:[CustomSearchTextField class]] || !_isScrollUp) {
- return [super resignFirstResponder];
- }
-
- if (_autoScrollUp) {
- // if (_customTextFieldSuperview == CustomTextFieldSuperviewIsScrollView) {
- // _targetSuperView = self.superview;
- // _superRect.origin.y = _superRect.origin.y < 0 ? 0.0f : _superRect.origin.y;
- // }
-
- [UIView animateWithDuration:kfAnimationDur animations:^{
- if ([_targetSuperView isKindOfClass:[UIScrollView class]]) {
- [(UIScrollView *)_targetSuperView setContentOffset:_contentOffset animated:NO];
- } else if (!CGRectIsEmpty(_superRect)) {
- _targetSuperView.frame = _superRect;
- NSLog(@"_superRect2 %@", NSStringFromCGRect(_superRect));
- }
- } completion:^(BOOL finished) {
- _isScrollUp = NO;
- }];
- }
-
- return [super resignFirstResponder];
- }
- - (void)goPrevField:(id)sender {
- [self resignFirstResponder];
- if ([self.delegate respondsToSelector:@selector(moveToPrevField:)]) {
- [self.delegate moveToPrevField:self];
- }
- }
- - (void)goNextField:(id)sender {
- [self resignFirstResponder];
- if ([self.delegate respondsToSelector:@selector(moveToNextField:)]) {
- [self.delegate moveToNextField:self];
- }
- }
- - (void)hideKeyboard:(id)sender {
- [self resignFirstResponder];
- if ([self.delegate respondsToSelector:@selector(willHideKeyboard:)]) {
- [self.delegate willHideKeyboard:self];
- }
- }
- // placeholder position
- - (CGRect)textRectForBounds:(CGRect)bounds {
- CGFloat margin = 16;
-
- CGRect inset = bounds;
- if (self.textAlignment == NSTextAlignmentLeft || self.textAlignment == NSTextAlignmentJustified || self.textAlignment == NSTextAlignmentNatural) {
- inset = CGRectMake(bounds.origin.x + margin, bounds.origin.y, bounds.size.width, bounds.size.height);
- }
- return inset;
- }
- // text position
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- CGFloat margin = 16;
-
- CGRect inset = bounds;
- if (self.textAlignment == NSTextAlignmentLeft || self.textAlignment == NSTextAlignmentJustified || self.textAlignment == NSTextAlignmentNatural) {
- inset = CGRectMake(bounds.origin.x + margin, bounds.origin.y, bounds.size.width, bounds.size.height);
- }
- return inset;
- }
- - (void)deleteBackward {
- if ([self.delegate respondsToSelector:@selector(deleteBackward:)] && [self.text isEmptyString]) {
- [self.delegate deleteBackward:self];
- return;
- }
- [super deleteBackward];
- }
- - (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled {
- [super setUserInteractionEnabled:userInteractionEnabled];
- UIImage *bgImage = [UIImage imageNamed:@"img_input_round_bg_active"];
- bgImage = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(kfBoxCap, kfBoxCap, kfBoxCap, kfBoxCap) resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- @end
- @implementation CustomTextField2
- // placeholder position
- - (CGRect)textRectForBounds:(CGRect)bounds {
- // CGFloat y = IOS_VERSION < 7.0f ? 6 : 0;
- CGFloat margin = 16;
- CGRect inset = CGRectMake(bounds.origin.x + margin, bounds.origin.y, bounds.size.width, bounds.size.height);
- return inset;
- }
- // text position
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- // CGFloat y = IOS_VERSION < 7.0f ? 6 : 0;
- CGFloat margin = 16;
- CGRect inset = CGRectMake(bounds.origin.x + margin, bounds.origin.y, bounds.size.width, bounds.size.height);
- return inset;
- }
- @end
- @implementation CustomSearchTextField
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.borderStyle = UITextBorderStyleNone;
- UIImage *bgImage = [UIImage imageNamed:@"input_wh_search"];
- if (bgImage) {
- bgImage = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(1, 22, 1, 1) resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- if (self.placeholder) {
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName:kUIPlaceHolderColor}];
- self.attributedPlaceholder = attrString;
- }
- }
- return self;
- }
- - (BOOL)becomeFirstResponder {
- //텍스트필드가 여러개일 경우, 다른 텍스트필드에서 resign을 처리하기 전에 호출되는 문제를 해결함.
- for (id textField in _targetSuperView.subviews) {
- if ([textField isKindOfClass:[UITextField class]] && [textField isFirstResponder]) {
- [textField resignFirstResponder];
- NSLog(@"regisgn t=%@, s=%@", textField, self);
- }
- }
- UIImage *bgImage = [UIImage imageNamed:@"input_wh_search_press"];
- if (bgImage) {
- bgImage = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(1, 22, 1, 1) resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- }
- return [super becomeFirstResponder];
- }
- - (BOOL)resignFirstResponder {
- UIImage *bgImage = [UIImage imageNamed:@"input_wh_search"];
- bgImage = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(1, 22, 1, 1) resizingMode:UIImageResizingModeStretch img:bgImage];
- [self setBackground:bgImage];
- if (self.autoScrollUp) {
- // if (_customTextFieldSuperview == CustomTextFieldSuperviewIsScrollView) {
- // _targetSuperView = self.superview;
- // _superRect.origin.y = _superRect.origin.y < 0 ? 0.0f : _superRect.origin.y;
- // }
- [UIView animateWithDuration:kfAnimationDur animations:^{
- if ([_targetSuperView isKindOfClass:[UIScrollView class]]) {
- [(UIScrollView *)_targetSuperView setContentOffset:_contentOffset animated:NO];
- } else if (!CGRectIsEmpty(_superRect)) {
- _targetSuperView.frame = _superRect;
- NSLog(@"_superRect2 %@", NSStringFromCGRect(_superRect));
- }
- }];
- }
- return [super resignFirstResponder];
- }
- // placeholder position
- - (CGRect)textRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 30.0f, 0);
- }
- // text position
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 30.0f, 0);
- }
- @end
- /*
- @implementation CustomTextField3
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- [self setBackground:[ACDUtil getStretchedImage:[UIImage imageNamed:@"bm_src_textfield_bg"] expectSize:self.bounds.size]];
- _cRect = self.frame;
- }
- return self;
- }
- - (void)awakeFromNib {
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- [self setBackground:[ACDUtil getStretchedImage:[UIImage imageNamed:@"bm_src_textfield_bg"] expectSize:self.bounds.size]];
- _cRect = self.frame;
- }
- - (void)drawRect:(CGRect)rect {
- CGRect tr = _cRect;
- tr.size.height = 29.0f;
- self.frame = tr;
- [self setNeedsLayout];
- }
- // placeholder position
- - (CGRect)textRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 26, 0);
- }
- // text position
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 26, 0);
- }
- @end
- @implementation CustomTextField4
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- [self setBackground:[ACDUtil getStretchedImage:[UIImage imageNamed:@"bm_src_textfield_bg2"] expectSize:self.bounds.size]];
- _cRect = self.frame;
- }
- return self;
- }
- - (void)awakeFromNib {
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- [self setBackground:[ACDUtil getStretchedImage:[UIImage imageNamed:@"bm_src_textfield_bg2"] expectSize:self.bounds.size]];
- _cRect = self.frame;
- }
- - (void)drawRect:(CGRect)rect {
- CGRect tr = _cRect;
- tr.size.height = 29.0f;
- self.frame = tr;
- [self setNeedsLayout];
- }
- // placeholder position
- - (CGRect)textRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 26, 0);
- }
- // text position
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 26, 0);
- }
- @end
- @implementation CustomTextField5
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- [self setBackground:[ACDUtil getStretchedImage:[UIImage imageNamed:@"st_src_textfield_bg"] expectSize:self.bounds.size]];
- _cRect = self.frame;
- }
- return self;
- }
- - (void)awakeFromNib {
- self.inputAccessoryView = [self generateAccessoryView];
- self.borderStyle = UITextBorderStyleNone;
- [self setBackground:[ACDUtil getStretchedImage:[UIImage imageNamed:@"st_src_textfield_bg"] expectSize:self.bounds.size]];
- _cRect = self.frame;
- }
- - (void)drawRect:(CGRect)rect {
- CGRect tr = _cRect;
- tr.size.height = 36.0f;
- self.frame = tr;
- [self setNeedsLayout];
- }
- // placeholder position
- - (CGRect)textRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 5, 0);
- }
- // text position
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- return CGRectInset(bounds, 5, 0);
- }
- @end
- */
- @implementation CustomMenuTextFieldMenu
- @end
- @implementation CustomMenuTextField
- //텍스트필드 컨텍스트 메뉴 커스터마이징
- - (void)setMenuItems:(NSArray *)menuItems {
- UIMenuController *menu = [UIMenuController sharedMenuController];
- menu.menuItems = menuItems;
- [menu update];
- }
- - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
- BOOL canPerform = NO;
- for (CustomMenuTextFieldMenu *menu in _menuItems) {
- canPerform = (action == menu.selector);
- if (canPerform)
- break;
- }
- return canPerform;
- }
- @end
|