码迷,mamicode.com
首页 > 其他好文 > 详细

自定义textView的placeholder和边框

时间:2016-06-24 10:45:44      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

 

想实现的效果:

技术分享

 

 

 

 

 

技术分享

技术分享

//

//  ViewController.m

//  A14 - 带占位符的textview

//

//  Created by vic fan on 16/6/24.

//  Copyright © 2016 李洪强. All rights reserved.

//

 

#import "ViewController.h"

 

@interface ViewController ()<UITextViewDelegate>

 

@property(nonatomic,strong)UILabel *label1;

@property(nonatomic,weak)UITextView *textView1;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    self.view.backgroundColor = [UIColor whiteColor];

    

    UITextView *textView = [[UITextView alloc] init];

    self.textView1 = textView;

    self.textView1.font = [UIFont systemFontOfSize:14];

    self.textView1.frame =CGRectMake(20, 50,[UIScreen mainScreen].bounds.size.width -50, 100);

    self.textView1.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    self.textView1.layer.borderColor = [UIColor blackColor].CGColor;

    self.textView1.layer.masksToBounds = YES;

    self.textView1.layer.borderWidth = 1;

    self.textView1.backgroundColor = [UIColor whiteColor];

    

    [self.view addSubview:self.textView1];

    self.textView1.hidden = NO;

    self.textView1.delegate = self;

    //其次在UITextView上面覆盖个UILable,UILable设置为全局变量。

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

    self.label1 = label1;

    self.label1.frame =CGRectMake(27, 17, [UIScreen mainScreen].bounds.size.width -50, 100);

    self.label1.text = @"请输入您的宝贵意见,建议,我们将不断完善";

    self.label1.enabled = NO;//lable必须设置为不可用

    self.label1.backgroundColor = [UIColor clearColor];

    self.label1.font = [UIFont systemFontOfSize:14];

    [self.view addSubview:self.label1];

    

    

}

  //  实现UITextView的代理

-(void)textViewDidChange:(UITextView *)textView

    {

        self.textView1.text = textView.text;

        if (textView.text.length == 0) {

            self.label1.text = @"请输入您的宝贵意见,建议,我们将不断完善";

        }else

            self.label1.text = @"";

        } 

    }

    

 

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

 

 

 

 

 

自定义textView的placeholder和边框

标签:

原文地址:http://www.cnblogs.com/LiLihongqiang/p/5613264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!