一、给UITextView绘制圆角,通过QuartzCore框架,操作CALayer可以给UITextView绘制圆角边框。
textView.layer.cornerRadius = 6
textView.layer.masksToBounds = YES
通过cornerRadius可设置圆角弧度。
二、设置UITextView背景图片,在UITextView区域内。
CGRect textViewFrame = CGRectMake(30.0,100.0,240.0,90.0);
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:[textView bounds]];
imageView.image = [UIImage imageNamed:@"background.png"];
[textView addSubview:imageView];
[textView sendSubviewToBack:imageView];
三、设置居中
textField.textAlignment = UITextAlignmentLeft; //水平左对齐
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //垂直居中
运行效果如下: