textView的提醒文字

如果我们想提交一些备注信息,会想到用textFiled和textView两种控件去实现

1.提醒文字是textFiled的特有属性,但是textFiled显示文本只有一行,不能实现我们输入较多文字的情况

2.textView可以自动适配多文字输入,但是没有提醒文字,这也不符合我们设计的需求

下面就有一种解决方法,话不多说,直接上代码

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #e44347 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #ffffff; min-height: 28.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #93c96a }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #c2349b }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #ffffff }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #00afca }
span.s1 { color: #d28f5a }
span.s2 { }
span.s3 { color: #c2349b }
span.s4 { color: #ffffff }
span.s5 { color: #00afca }
span.s6 { color: #93c96a }
span.s7 { color: #8b84cf }
span.s8 { color: #e44347 }

#import "YSCreateScheduleRemarkView.h"

#import "Masonry.h"

@interface YSCreateScheduleRemarkView ()

@end

@implementation YSCreateScheduleRemarkView

- (instancetype)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:frame]) {

[self initUI];

}

return self;

}

- (void)initUI {

self backgroundColor = [UIColor whiteColor];

_textView = [[UITextView alloc] init];

_textView.font = [UIFont systemFontOfSize:15];

[self addSubview:_textView];

[_textView mas_makeConstraints:^(MASConstraintMaker *make) {

make.top.mas_equalTo(self.mas_top);

make.left.mas_equalTo(self.mas_left).offset(10);

make.bottom.mas_equalTo(self.mas_bottom);

make.right.mas_equalTo(self.mas_right).offset(-10);

}];

}

- (void)setplaceholder:(NSString *)placeholder {

UILabel *placeholderLabel = [[UILabel alloc] init];

placeholderLabel.text = placeholder;

placeholderLabel.numberOfLines = 1;

placeholderLabel.textColor = [UIColor lightGrayColor];

[placeholderLabel sizeToFit];

placeholderLabel.font = _textView.font;

[_textView addSubview:placeholderLabel];

[_textView setValue:placeholderLabel forKey:@"_placeholderLabel"];

}

@end

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #e44347 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #ffffff; min-height: 28.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #00afca }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #ffffff }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #c2349b }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #93c96a }
span.s1 { color: #d28f5a }
span.s2 { }
span.s3 { color: #c2349b }
span.s4 { color: #ffffff }
span.s5 { color: #93c96a }
span.s6 { color: #00afca }
span.s7 { color: #e44347 }
span.s8 { color: #8b84cf }
span.s9 { font: 24.0px "PingFang SC"; color: #e44347 }

#import "ViewController.h"

#import "YSCreateScheduleRemarkView.h"

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate>

{

UITableView *table;

}

@property (nonatomic, strong) YSCreateScheduleRemarkView *createScheduleRemarkView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColorwhiteColor];

table = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];

table.delegate = self;

table.dataSource = self;

[self.view addSubview:table];

[table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CreateScheduleCell"];

}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return  4;

}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

return 0.01;

}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

return 135;

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

_createScheduleRemarkView = [[YSCreateScheduleRemarkView alloc] init];

_createScheduleRemarkView.textView.delegate = self;

[_createScheduleRemarkView setplaceholder:@"备注"];

return _createScheduleRemarkView;

}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CreateScheduleCell"];

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CreateScheduleCell"];

cell.textLabel.text = @"12111";

return cell;

}

- (void)textViewDidBeginEditing:(UITextView *)textView {

[self showKeyboardManager:1]:

}

- (void)textViewDidEndEditing:(UITextView *)textView {

[self showKeyboardManager:0];

}

- (void)showKeyboardManager:(NSInteger)integer {

[UIView animateWithDuration:0.2f animations:^{

table.frame = CGRectMake(0, integer == 1 ? -44*4 : 0, 375, 667);

}];

}

时间: 2024-08-06 11:39:22

textView的提醒文字的相关文章

TextView 设置部分文字颜色及点击事件SpannableString

设置TextView中一部分文字的颜色及点击事件. SpannableString gotoMsgListStr = new SpannableString("消息列表"); gotoMsgListStr.setSpan(new ClickableSpan() { @Override public void onClick(View widget) { startActivity(new Intent(OrderPayStatusActivity.this, MsgListActivi

检测textView里面的文字是否包含emoji表情字符

用这个方法可以检测出来,返回bool值 - (BOOL)stringContainsEmoji:(NSString *)string { __block BOOL returnValue = NO; [string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *subs

让TextView里面的文字逐个显示的动画效果实现

最近使用TextView时想要实现里面的文字逐个显示的动画效果,就如同打字一样. 主要实现思想:新建一个TextView的派生类,先将要逐个显示的字符串保存变量 mOriginalStr 中,然后启动新线程,每隔一段时间使用 Handler 类对象的sendEmptyMessage(int what) 方法发送消息,让 Handler 对象将mOriginal中的字符串逐个添加到TextView中进行显示. 代码实现如下: 1 /** 2 * Created by Haoye on 2016/1

自定义属性之LinearLayout ImageView TextView模拟图片文字按钮

一.资源文件: 1.文字选择器: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="#FF111111"/>

Android中TextView中的文字设置为不同颜色

questionDesTextView=(TextView)findViewById(R.id.question_des); SpannableStringBuilder builder = new SpannableStringBuilder(questionDesTextView.getText().toString()); //ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色 ForegroundColorSpan blackSpan

Android TextView设置多彩文字

在应用开发中时常会遇到需要在一段文字中插入几个不一样颜色文字的需求; 以前本人都是用多个TextView拼起来,不仅感觉很蠢,操作起来也蛮恶心; 直到接触到了SpannableStringBuilder,感觉整个人都好了; 在我搭建界面布局,会有一些带String占位符的默认文字,如:"现在的气温是:%s","今天天气:%1$s,最高气温:%2$s,最低气温:%3$s,降雨率:%4$s,pm2.5:%5$s."; 之后在获取到数据时,直接String.format(

Android中动态更新TextView上的文字

示例代码: 1.新线程,定时更新文字 class testThread extends Thread{ public void run() { Message message = new Message(); mHandler.sendMessage(message); } } //在handler中更新UI private Handler mHandler = new Handler(){ public void handleMessage(Message msg) { textView.se

Andriod TextView多颜色显示文字

需求:如下图所示,一段文字中包含电话号码,需要修改电话号码的样式,甚至给它加点击事件. 解决办法: 本例主要以TextView为例,但是可以用于Button等控件中.SpannableStringBuilder对象的setSpan(Object what, int start, int end, int flags)方法可以设置多次,并且每次设置的ParcelableSpan子类效果是叠加的.setSpan(Object what, int start, int end, int flags)参

android TextView 设置部分文字背景色和文字颜色

通过SpannableStringBuilder来实现,它就像html里边的<span>元素改变指定文字的文字颜色或背景色 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Str