繁体   English   中英

UITextView中带有换行的exclusionPaths错误

[英]Incorrect exclusionPaths with new lines in a UITextView

当textView具有换行符时,exclusionPaths存在问题:

这是我的代码:

- (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];

}

结果如下:

在此处输入图片说明

问题在于换行符使exclusionPaths超出其应有的大小。 在此处还描述了该问题: iOS 7 UITextView中的换行符打破了文本工具包排除区域的环绕 ,但它显示了如何使用Interface Builder创建UITextView时解决此iOS 7错误。 如何以编程方式解决此问题? 谢谢!

因此要禁用的获胜属性是“ scrollEnabled”:

textView.editable = NO
textView.scrollEnabled = NO

上面的代码解决了exclusionPaths的问题

如果需要可编辑的textView,请尝试在TextView的子类中使用此方法

 - (void)layoutSubviews
{
[super layoutSubviews];

self.contentOffset = CGPointMake(0, 0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM