UITextView

//将文本视图附加到一个已有的试图对象上
-(void)loadView{
    [super loadView];
    CGRect viewRect = CGRectMake(0, 100, 320, 200);
    
    UITextView *textView = [[UITextView alloc] initWithFrame:viewRect];
    
    //颜色
    UIColor *myColorHue = [UIColorcolorWithHue:120.0/360.0saturation:0.75brightness:0.50alpha:1.0];
    //    UIColor *myColorRGB = [UIColor colorWithRed:0.75 green:1.0 blue:0.75 alpha:1.0];
    //    UIColor *myWhiteTransparentColor = [UIColor colorWithWhite:1.0 alpha:0.50];
    //    UIColor *myColor = [UIColor redColor]; 
    textView.textColor = myColorHue;
    
    //字体与大小
    UIFont *myFixed = [UIFont fontWithName:@"Courier New" size:10.0];
    //    UIFont *mySystemFont = [UIFont systemFontOfSize:12.0];
    //    UIFont *myBoldSystemFont = [UIFont boldSystemFontOfSize:12.0];
    //    UIFont *myItalicSystemFont = [UIFont italicSystemFontOfSize:12.0];
    textView.font = myFixed;
    
    textView.editable = NO;  //设置为不可编辑,默认的为可编辑
    
    //赋予内容
    textView.text = @"hello .bit hold ";
    
    //分别为左中右对齐
    textView.textAlignment = UITextAlignmentLeft;
    //    textView.textAlignment = UITextAlignmentCenter;
    //    textView.textAlignment = UITextAlignmentRight;
    
    //直接赋值
    int nBottles = 100;
    NSString *myFormattedString = [[NSString alloc]initWithFormat:@"%d bottles of beer on the wall",nBottles];
    textView.text = myFormattedString;
    
    //读取文件
    //    NSString *myFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Document/file.txt"];
    //    NSString *myFileString = [NSString stringWithContentsOfFile:myFile encoding:nil error:nil];
    //    textView.text = myFileString;
    
    //键盘属性
    textView.keyboardType = UIKeyboardTypePhonePad; //键盘风格,8种
    textView.keyboardAppearance = UIKeyboardAppearanceAlert; //键盘外观,两种:浅灰色或深灰色
    textView.returnKeyType = UIReturnKeyGo; //回车键的风格 11种
    textView.autocapitalizationType = UITextAutocapitalizationTypeNone;//自动大写功能 4种
    textView.autocorrectionType = UITextAutocorrectionTypeDefault;  //自动更正
    textView.secureTextEntry = YES; //安全文本输入,即输入后会显示*号
    
    [self.view addSubview:textView];
}
复制代码

 

UITextView协议:

//点击开始编辑:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
- (void)textViewDidBeginEditing:(UITextView *)textView;

 

//结束编辑

- (BOOL)textViewShouldEndEditing:(UITextView *)textView;

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

 

//更改内容
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
- (void)textViewDidChange:(UITextView *)textView;


- (void)textViewDidChangeSelection:(UITextView *)textView;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值