1、设置UITextView的属性
- textView.returnKeyType
= UIReturnKeyDefault;//返回键的类型 - textView.keyboardType
= UIKeyboardTypeDefault;//键盘类型
textView.scrollEnabled= YES;//是否可以拖动 - textView.autoresizingMask
= UIViewAutoresizingFlexib leHeight;//自适应高度
2、设置UITextView圆角问题
先引入#import
textView.layer.cornerRadius
- textView.layer.masksToBounds
= YES;
3、给TextView加一个有色边框,并设置背景图片
//给图层添加一个有色边框
- textView.layer.borderWidth
= 5;
textView.layer.borderColor= [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:0.5] CGColor];
textView.layer.contents = (id)[UIImage imageNamed:@"xxxxx"].CGImage; //给图层添加背景图片
4、UITextView自定选择文字后的菜单
在ViewDidLoad中加入:
- -
(void)viewDidLoad
{
- [super
viewDidLoad];
self._textView
_textView.font
- [self.view
addSubview:_textView];
UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"分享到新浪微博" action:@selector(fun)];
- UIMenuController
*menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObject:menuItem]];
- [menuItem
release];
}
@selector里面的fun方法是自己写的函数,也就是说点击了我们自定义的菜单项后会触发的方法。
然后还得在代码里加上一个方法:
- -(BOOL)canPerformAction:(SEL)action
withSender:(id)sender
{
- if(action
==@selector(changeColor) || action == @selector(copy:))
{
if(_textView.selectedRange.length>0)
- return
YES;
}
return
- }
- -(void)
fun
{
NSLog(@"%@",[_textView.text substringWithRange:_textView.selectedRange]);
view plaincopy
- }