扫码关注官方订阅号
哈哈 比如这是 UITextView 中最开始的一段文字,要达到这种效果,不能让光标进入 哈哈 这段文字中,只能在其后面开始输入 ?
哈哈
学习是最好的投资!
可以用 textContainer.exclusionPaths 属性在 UITextView 给圈一块地出来,然后加上一个 Label 显示你想显示的文字,即不可编辑,当然也可以是图片或其他什么东西。
textContainer.exclusionPaths
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.
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以用
textContainer.exclusionPaths
属性在 UITextView 给圈一块地出来,然后加上一个 Label 显示你想显示的文字,即不可编辑,当然也可以是图片或其他什么东西。