UILabel太大而无法显示忽略虚假层

时间:2018-05-08 14:27:59

标签: objective-c uilabel

我想在滚动视图中用UILabel显示一本书的整章。但似乎内容太大而无法显示,并出现以下错误:

[2835:157182] -[<_UILabelContentLayer: 0x60400023b040> display]: Ignoring bogus layer size (378.666667, 883959.333333), contentsScale 3.000000, backing store size (1136.000000, 2651878.000000)

我搜索了答案,有些人建议我应该使用CATiledLayer来解决这个问题,但他们并没有明确说明如何做到这一点,任何人都可以提供一些帮助?

谢谢,

- (void)viewDidLoad {
    [super viewDidLoad];


    /*** Init the scrollview and the label ***/

    UIScrollView *scrollView= [UIScrollView new];
    scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:scrollView];

    UILabel *scrollViewLabel = [[UILabel alloc] init];

    scrollViewLabel.numberOfLines = 0;
    scrollViewLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [scrollView addSubview:scrollViewLabel];

    scrollViewLabel.text = @"";
    NSArray *array = [Utils getCharptersWithName:@"mybook"];



    for(NSDictionary *dic in array){
        scrollViewLabel.text = [scrollViewLabel.text stringByAppendingString:[dic objectForKey:@"content"]];
    }

    NSLog(@"%@", scrollViewLabel.text);


    /*** Auto Layout ***/

    NSDictionary *views = NSDictionaryOfVariableBindings(scrollView, scrollViewLabel);

    NSArray *scrollViewLabelConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollViewLabel(scrollView)]" options:0 metrics:nil views:views];
    [scrollView addConstraints:scrollViewLabelConstraints];

    scrollViewLabelConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollViewLabel]|" options:0 metrics:nil views:views];
    [scrollView addConstraints:scrollViewLabelConstraints];

    NSArray *scrollViewConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[scrollView]-|" options:0 metrics:nil views:views];
    [self.view addConstraints:scrollViewConstraints];

    scrollViewConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[scrollView]-|" options:0 metrics:nil views:views];
    [self.view addConstraints:scrollViewConstraints];



    // Do any additional setup after loading the view.
}

0 个答案:

没有答案