【问题标题】:iOS - Making CATextLayer scrollableiOS - 使 CATextLayer 可滚动
【发布时间】:2013-01-28 13:49:32
【问题描述】:

我想让这个层内的文本可滚动。我目前能够在图像上显示以下文本。但是,如果文本太长,它的一部分不会显示出来。因此我想垂直滚动它。对 scrollView 对象不是很熟悉。有人可以帮忙吗?

// Create the new layer object
boxLayer = [[CATextLayer alloc] init];

// Give it a size
[boxLayer setBounds:CGRectMake(0.0, 0.0, 500.0, 500.0)];

// Give it a location
[boxLayer setPosition:CGPointMake(300.0, 350.0)];

// Make half-transparent red the background color for the layer
UIColor *reddish = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];

// Get CGColor object with the same color values
CGColorRef cgReddish = [reddish CGColor];
[boxLayer setBackgroundColor:cgReddish];

// Make it a sublayer on the view's layer
[self.view.layer addSublayer:boxLayer];

// Create string
NSString *text2 = @"The article was about employment.\nHe leafed through it in an instant.\nHis feeling of anxiety resurfaced and he closed the magazine.\n\n-Hm…, he breathed.\n\n-Have you been looking for work long?, asked the stranger at his side.\nThe article was about employment.\nHe leafed through it in an instant.\nHis feeling of anxiety resurfaced and he closed the magazine.\n\n-Hm…, he breathed.\n\n-Have you been looking for work long?, asked the stranger at his side.\nThe article was about employment.\nHe leafed through it in an instant.\nHis feeling of anxiety resurfaced and he closed the magazine.\n\n-Hm…, he breathed.\n\n-Have you been looking for work long?, asked the stranger at his side.";

// Set font
[boxLayer setFont:@"MarkerFelt-Thin"];

// Set font size
[boxLayer setFontSize:20.0];

[boxLayer setAlignmentMode:kCAAlignmentLeft];

boxLayer.wrapped = YES;

// Assign string to layer
[boxLayer setString:text2];

【问题讨论】:

标签: ios text scroll layer catextlayer


【解决方案1】:

您不能直接滚动 CATextLayer。 首先,您必须在 UIView 中添加 CATextLayer,而不是在 ScrollView 中添加 UIView。 现在您可以滚动 CATextLayer。 请告诉我它是否适合您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多