Ngay từ cái nhìn đầu tiên, câu hỏi của tôi trông rất đơn giản, nhưng có vẻ như tôi thực sự không thể tìm ra giải pháp. Đây là nội dung: Tôi muốn tính toán hộp giới hạn của chuỗi CATextLayer. Dưới đây là những gì tôi làm:Cách tính toán hộp giới hạn của chuỗi CATextLayer?
CATextLayer *textLayer = [CATextLayer layer];
textLayer.frame = CGRectMake(80, 0.0f, 36.0f, 18.0f);
textLayer.string = @"12";
textLayer.fontSize = [UIFont systemFontSize];
textLayer.foregroundColor = [UIColor whiteColor].CGColor;
NSLog(@"(width,height)=(%f,%f)",
[textLayer.string sizeWithFont:textLayer.font].width,
[textLayer.string sizeWithFont:textLayer.font].height);
Vấn đề là đầu ra luôn là: (chiều rộng, chiều cao) = (8.000000,0.000000)