哈哈
比如这是 UITextView 中最开始的一段文字,要达到这种效果,不能让光标进入 哈哈
这段文字中,只能在其后面开始输入 ?
可以用 textContainer.exclusionPaths
属性在 UITextView 给圈一块地出来,然后加上一个 Label 显示你想显示的文字,即不可编辑,当然也可以是图片或其他什么东西。
UIFont *defaultFont = [UIFont systemFontOfSize:13.0];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(30, 100, 100, 100)];
textView.font = defaultFont;
textView.backgroundColor = [UIColor lightGrayColor];
UIBezierPath* aObjBezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 50, 10)];
textView.textContainer.exclusionPaths = @[aObjBezierPath];
[self.view addSubview:textView];
UILabel *paddingLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 40, 20)];
paddingLabel.text = @"备注:";
paddingLabel.font = defaultFont;
paddingLabel.textColor = [UIColor redColor];
[textView addSubview:paddingLabel];
Available in iOS 7.0 and later.