UITextView如何绘制圆角和添加背景图片
来源:互联网 发布:苹果 淘宝 编辑:程序博客网 时间:2024/05/21 20:24
[转]UITextView如何绘制圆角和添加背景
UITextView 修改样式资料比较少,最近摸索了下,总结了以下几种方式:
一、给UITextView绘制圆角,通过QuartzCore框架,操作CALayer可以给UITextView绘制圆角边框。
textView.layer.cornerRadius = 6
textView.layer.masksToBounds = YES
通过cornerRadius可设置圆角弧度。
二、UITextView和UIImageView组合,将背景图片制作好加载进UIImageView。
CGRect imageViewFrame = CGRectMake(30.0,100.0,240.0,90.0);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageViewFrame];
imageView.image = [UIImage imageNamed:@"background.png"];
imageView.userInteractionEnabled = YES;
CGRect textViewFrame = CGRectMake(5.0,5.0,230.0,80.0);
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
textView.backgroundColor = [UIColor clearColor];
[imageView addSubview:textView];
设置imageView.userInteractionEnabled = YES,让textView响应触碰事件。
三、设置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];
看到的另一种方法,这个方法我已经实验过了,可行:
- UITextView *textView = [[UITextView alloc]initWithFrame: window.frame];
- textView.text = @"text\n text\n text";
- UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
- imgView.image = [UIImage imageNamed: @"myImage.jpg"];
- [self.view addSubview: imgView];
- [self.view sendSubviewToBack: imgView];
- [self.view addSubview: textView];
- 但是注意,5,6,7行我修改过,原来的代码是:
- [textView addSubview: imgView];
- [textView sendSubviewToBack: imgView];
- [self.view addSubview: textView];
- 这样实际上是把imgview作为了textview的一个字视图先加进来,然后把textview在加入到当前视图,这样做的不好处就是imgview因为是textview的一个字视图,所以大小跟textview一样,也就是说你没法设置整个页面的背景,如果你的textview不是全屏的话
- UITextView如何绘制圆角和添加背景图片
- UITextView添加背景图片
- 给UITextView添加背景图片
- UITextView的创建/背景图片/边框和颜色/圆角等
- Swift开发教程--如何给UITextView添加圆角边框
- Swift UITextView添加背景图片,设定光标位置
- UITextView添加圆角边框
- UITextView添加圆角边框
- UITextView添加圆角边框
- UITextView如何添加placehoderLabel
- 如何给UITextView 添加连接
- uitextview的边框添加圆角
- 如何给对话框添加背景图片
- 如何给View添加背景图片
- 如何给对话框添加背景图片
- UILable上如何添加背景图片
- 如何给MFC添加背景图片
- Symbian中如何绘制背景图片问题
- vue.js 2.0父子组件学习入门套路(推荐相关阅读)
- Excel表格数据怎么行列倒置,怎么行列切换
- Tomcat性能优化
- 机器学习实验(十一):基于WiFi fingerprints用自编码器(Autoencoders)和神经网络(Neural Network)进行定位_2(keras版)
- excel match 某个值是否在特定列
- UITextView如何绘制圆角和添加背景图片
- k近邻算法
- 亲自实践Andfix 流程记录
- OpenAL播放pcm或wav数据流-windows/ios/android(一)
- React Native客户端服务器分开集成方案
- excel数据以千位单位K显示
- 自动化笔记-iframe
- Spark运行模式
- android键盘弹出、关闭、遮挡问题