UITextView的placeholder属性
来源:互联网 发布:足彩数据接口 编辑:程序博客网 时间:2024/05/01 08:51
写项目的时候,发现UITextField并没有换行的属性,所以采用UITextView来实现,最后发现一个问题,UITextView并没有placeholder(占位符)属性。
解决方案:直接看代码如下:
#import "DiscussViewController.h"
#import "ProgressHUD.h"
#import "TitleViewController.h"
@interface DiscussViewController ()<UITextViewDelegate>
@property (nonatomic, strong) UITextView *discussView;
@property (nonatomic, strong) UILabel *lable;
@property (nonatomic, strong) UIButton *sendBtn;//发送按钮
@end
@implementation DiscussViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"评论";
[self showBarButtonWithImage:@"back_arrow"];
self.view.backgroundColor = [UIColor colorWithRed:232/255.0 green:233/255.0 blue:232/255.0 alpha:1.0];
[self.view addSubview:self.discussView];
[self.view addSubview:self.lable];
self.sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.sendBtn.frame = CGRectMake(0, 0, 60, 44);
[self.sendBtn setTitle:@"发送" forState:UIControlStateNormal];
//调整btn标题所在的位置,距离btn顶部,左边,底部,右边的距离
[self.sendBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[self.sendBtn addTarget:self action:@selector(sendBtnAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:self.sendBtn];
rightBarBtn.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = rightBarBtn;
}
#pragma mark ------------- lazy Loading
- (UITextView *)discussView{
if (_discussView == nil) {
self.discussView = [[UITextView alloc] initWithFrame:CGRectMake(20, KScreenWidth/10, KScreenWidth-40, KScreenWidth/2)];
self.discussView.backgroundColor = [UIColor whiteColor];
self.discussView.hidden = NO;
self.discussView.delegate = self;
// self.discussView.text = @"_说点什么吧";
self.discussView.textColor = [UIColor lightGrayColor];
self.discussView.font = [UIFont systemFontOfSize:15.0f];
}
return _discussView;
}
- (UILabel *)lable{
if (_lable == nil) {
self.lable = [[UILabel alloc] initWithFrame:CGRectMake(20, KScreenWidth/10, KScreenWidth-40, KScreenWidth/2)];
self.lable.text = @"_说点什么吧~";
self.lable.enabled = NO;
self.lable.numberOfLines = 0;
self.lable.backgroundColor = [UIColor clearColor];
}
return _lable;
}
//实现UITextView的代理
-(void)textViewDidChange:(UITextView *)textView
{
self.discussView.text = textView.text;
if (textView.text.length == 0) {
self.lable.text = @"_说点什么吧";
}else{
self.lable.text = @"";
}
}
#pragma mark --------- 发送按钮的点击方法
- (void)sendBtnAction{
if (self.discussView.text.length <= 0) {
[ProgressHUD showError:@"评论内容不能为空呦"];
}else{
[ProgressHUD showSuccess:@"发送成功"];
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
//点击空白处回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.discussView resignFirstResponder];
}
- UITextView的placeholder属性
- UITextView的placeholder属性
- 解决UITextView的placeholder属性
- 实现placeholder属性的UITextView
- 实现placeholder属性的UITextView
- 自定义 UITextView 的 placeholder 属性
- ios UITextView的placeholder属性实现
- UITextView添加placeholder属性
- UITextView添加placeholder属性
- UITextView添加placeholder属性
- UItextview 怎么实现placeholder属性
- UITextView 的placeholder
- UITextView 的placeholder
- UITextView的placeholder
- UITextView的placeholder猥琐做法
- iphone自定义UITextView的placeholder
- UITextView 实现placeholder的方法
- UITextView 实现placeholder的方法
- Topcoder Open 2016 R1A
- 【BZOJ1072】[SCOI2007]排列perm【暴搜】
- linux下的hosts.allow和hosts.deny
- 关于指针与类的内存分布问题(问题思考来自《程序员面试宝典》)
- android 判断网络是否可用
- UITextView的placeholder属性
- Android Service Security
- libc、glibc和glib的关系
- Lua: lua_call/lua_pcall/lua_cpcall的用法
- Javascript数组、json对象基本操作
- WebView的方法onScrollChanged不被调用的原因
- google 搜索帮助
- iOS开发-UICollectionView实现瀑布流
- Eclipse出现Failed to create the part's controls