UITextView

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(100, 50, 200, 150)];
    textView.tag = 10;
    textView.backgroundColor = [UIColor whiteColor];
    textView.text = @"welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!welcome to my city!";
    textView.textColor = [UIColor blackColor];
    textView.font = [UIFont fontWithName:@"Arial" size:15];
//    textView.secureTextEntry = YES;
    textView.delegate = self;
    textView.returnKeyType = UIReturnKeyDone; //返回键类型
    textView.keyboardType = UIKeyboardTypeDefault;  //键盘类型
    textView.scrollEnabled = YES; //是否可以拖动
    textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    
    [self.view addSubview:textView];
    [textView release];
}
//按回车键盘消失
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text; {
    
    if ([@"\n" isEqualToString:text] == YES) {
        UITextView *tView = (UITextView*)[self.view viewWithTag:10];
        [tView resignFirstResponder];
        return NO;
    }
    return YES;
}
/按非键盘位置的其它任意位置让键盘消失

//该方法需要先把XIB里的Objects下的UIView类名改为UIControl,然后右键点击Objects下的Control,把鼠标放开事件连线到File`s Owner

- (IBAction)backgroundTap:(id)sender {
    UITextView *tView = (UITextView*)[self.view viewWithTag:10];
    [tView resignFirstResponder];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值