OC Extension TextView

一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。

OC 项目底层框架(万能)

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;

效果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冯汉栩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值