一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。
2021.2.16 FHXPlaceholderTextView下载链接
2021.5.26 OC Extension FHXPlaceholderTextView下载链接
说明系统自带的UITextView是没有输入提示的UITextField才有,所以自己写了一个FHXPlaceholderTextView。
PlaceholderAndLimitTextView这个右下角还带有限制文字输入的提示(下面有效果图)
先讲 FHXPlaceholderTextView
/** 占位文字 */
@property (nonatomic, copy) NSString *placeholder;
/** 占位文字的颜色 */
@property (nonatomic, strong) UIColor *placeholderColor;
/** 占位文字的大小 */
@property (nonatomic, strong) UIFont *placeholderFont;
/** 占位文字的左边距离 */
@property (nonatomic, assign) CGFloat placeholderLeftDistance;
/** 占位文字的右边距离 */
@property (nonatomic, assign) CGFloat placeholderTopDistance;
使用
self.textView = [FHXPlaceholderTextView new];
self.textView.addTo(self).bgColor([Color randomColor]);
self.textView.placeholder = @"写下您宝贵的建议,我们将尽快处理";
self.textView.placeholderTopDistance = 15;
self.textView.placeholderLeftDistance = 20;
self.textView.placeholderFont = [UIFont systemFontOfSize:16];
self.textView.font = [UIFont systemFontOfSize:16];
self.textView.placeholderColor = [Color nonActivated];
//上下左右的边距 使用textContainerInset设置top、left、botto, right
self.textView.textContainerInset = UIEdgeInsetsMake(15, 20, 5, 5);
//当光标在最后一行时,始终显示低边距,需使用contentInset设置bottom.
self.textView.contentInset = UIEdgeInsetsMake(0, 0, 15, 0);
//防止在拼音打字时抖动
self.textView.layoutManager.allowsNonContiguousLayout=NO;
效果
PlaceholderAndLimitTextView
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class PlaceholderAndLimitTextView;
@protocol PlaceholderAndLimitTextViewDelegate <NSObject>
-(void)placeholderAndLimitTextView:(PlaceholderAndLimitTextView *)textView returnCurrentValue:(NSString *)value;
@end
@interface PlaceholderAndLimitTextView : UIView
@property (nonatomic,weak) id<PlaceholderAndLimitTextViewDelegate> delegate;
/** 占位文字 */
@property (nonatomic, copy) NSString *placeholder;
/** 占位文字的颜色 */
@property (nonatomic, strong) UIColor *placeholderColor;
/** 占位文字的大小 */
@property (nonatomic, strong) UIFont *placeholderFont;
/** 占位文字的左边距离 */
@property (nonatomic, assign) CGFloat placeholderLeftDistance;
/** 占位文字的右边距离 */
@property (nonatomic, assign) CGFloat placeholderTopDistance;
/** textView背景颜色 */
@property (nonatomic, strong) UIColor *bgColor;
/** textView内容文字大小 */
@property (nonatomic, strong) UIFont *contentFont;
/** 限制文字大小 */
@property (nonatomic, strong) UIFont *limitFont;
/** 限制文字颜色 */
@property (nonatomic, strong) UIColor *limitColor;
/** 限制文字总数 */
@property (nonatomic, assign) NSInteger limitAllCount;
/** 当前文字个数 */
@property (nonatomic, assign) NSInteger limitCurrentCount;
@end
NS_ASSUME_NONNULL_END
使用
self.textView.addTo(self.view).borderRadius(8) .xywh(rectTextView.origin.x,rectTextView.origin.y,Phone_Width-30, 200);
self.textView.placeholder = @"写下您宝贵的建议,我们将尽快处理";
self.textView.placeholderColor = [Color nonActivated];
self.textView.placeholderFont = [UIFont systemFontOfSize:16];
self.textView.placeholderTopDistance = 15;
self.textView.placeholderLeftDistance = 20;
self.textView.bgColor = [Color backgroung];
self.textView.contentFont = [UIFont systemFontOfSize:16];
self.textView.limitFont = [UIFont systemFontOfSize:16];
self.textView.limitColor = [Color nonActivated];
self.textView.limitCurrentCount = 0;
self.textView.limitAllCount = 10;
self.textView.delegate = self;
效果