My CATextlayer support only 1 line otherwise the text is cut.
trying to set text content like UILabel Behaviour... is it possible?
set "number of lines"
adjust text size by static CATextLayer frame
CATextLayer *text_layer= [[CATextLayer alloc] init];
[text_layer setBackgroundColor:[UIColor clearColor].CGColor];
[text_layer setBackgroundColor:[UIColor blueColor].CGColor];
[text_layer setForegroundColor:layers.textColor.CGColor];
[text_layer setAlignmentMode:kCAAlignmentCenter];
[text_layer setBorderColor:layers.borderColor.CGColor];
[text_layer setFrame:CGRectMake(0,0,200,50)]; //note: frame must be static
[text_layer setString:@"thank you for your respond"];
text_layer.wrapped = YES;
[text_layer setAlignmentMode:kCAAlignmentCenter];
Your problem is this line right here,
[text_layer setFrame:CGRectMake(0,0,200,50)];
. I don't think a CATextLayer would lay itself out to accommodate multiple lines. It will only re-draw the text to wrap within the layer's bounds. Try adjusting your text layer's frame based on the text being set. You can create aUILabel
instance, to calculate the frame for having multiline text with word wrapping and set it to yourCATextLayer
instance.Here's a
UILabel
category to calculate text size for multiline text with word wrapping:Create a
UILabel
instance, and use thesizeForWrappedText
to get the size. Something like this: