当 textView 具有换行符时,我遇到排除路径问题:
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] init];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 333, 360, 480)];
view.frame = CGRectMake(50, 0, 50, 50);
view.backgroundColor = [UIColor blackColor];
NSLog(@"%@", NSStringFromCGRect(view.frame));
[textView addSubview:view];
CGRect relativeRect = [textView convertRect:view.bounds fromView:view];
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:relativeRect];
textView.text = @"asddsaadasddsasdasdjsdhfjkdhkjdhfgjkldhsgfjlk\n\nhfdsgjklhdfsljkghdklfjgshdgjklfshdfgjklhfglkjdshjklgfdshjklgdfshkljfdsghfjkldghlkjfdghskljgdfhslkjgdfshjklgfdshjkgfdshlkjgdfhskljdgfhsjklgdhsjklfgdshjkglfdshjklgfdshlkjfgdhjklgdfshjdfkslghkjfdlsghjkldsfghjkhdfsgkjlhjgkldfshgdflksjhfdksgjhdfkjlgshfkljdshgjkdfhskjglhdfsjkghdfkjglhdsfkjghkljdfhgkjlhdsfkjlghjkldsfghjklhgsfdjklhgsdfkjlghdsfklgfdhsklg";
textView.textContainer.exclusionPaths = @[bezierPath];
[self.view addSubview:textView];
}
结果如下:
问题是新行字符使排除路径比应有的大。此处还描述了该问题:Newlines in iOS 7 UITextView breaking Text Kit exclusion zone wrapping ,但它展示了如果使用 Interface Builder 创建 UITextView 如何修复此 iOS 7 错误。我将如何以编程方式解决这个问题?谢谢!
最佳答案
因此,要禁用的获胜属性是“scrollEnabled”:
textView.editable = NO
textView.scrollEnabled = NO
上面的代码解决了我的排除路径问题
关于ios - UITextView 中包含新行的排除路径不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681960/