0

我想让这个文本在图层中滚动。我目前能够在图像上显示以下文本。但是,如果文本太长,它的一部分不会显示出来。因此我想垂直滚动它。对 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];
4

1 回答 1

0

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

于 2014-01-22T08:44:40.020 回答