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 を直接スクロールすることはできません。まず、ScrollView 内に UIView を追加するよりも、UIView 内に CATextLayer を追加する必要があります。CATextLayer をスクロールできるようになりました。それがあなたのために働くかどうか教えてください。

于 2014-01-22T08:44:40.020 に答える