简体   繁体   English

AutoLayout和CATextLayer iOS7

[英]AutoLayout and CATextLayer iOS7

I'm trying to animate text changing with CATextLayer. 我正在尝试使用CATextLayer更改文本的动画。

   intValueLayer = [CATextLayer layer];
   [intValueLayer setFrame:self.lblIntPart.bounds];
   [[self.lblIntPart layer] addSublayer:intValueLayer];

I'm using AutoLayout on my view and I know that setFrame method not working properly. 我在视图上使用了AutoLayout,并且知道setFrame方法无法正常工作。 In my case frame of CATextLayer smaller than self.lblIntPart .So, how can I add constraints to my TextLayer or display it with the same frame as self.llbIntPart. 在我的情况下,CATextLayer的框架小于self.lblIntPart。因此,如何为我的TextLayer添加约束或以与self.llbIntPart相同的框架显示约束。

Thank you! 谢谢!

All method looks like: 所有方法如下所示:

   intValueLayer = [CATextLayer layer];
    [intValueLayer setFrame:self.lblIntPart.bounds];
    [[self.lblIntPart layer] addSublayer:intValueLayer];

    [intValueLayer setAlignmentMode:@"center"];
    [intValueLayer setForegroundColor:self.category.colour.colour.CGColor];
    [intValueLayer setFont:CFBridgingRetain(@"DilleniaUPCBold")];
    [intValueLayer setFontSize:96.0f * scale];
    intValueLayer.contentsScale = [UIScreen mainScreen].scale;

    [intValueLayer setString:@"0"];

After trying to reproduce your issue, here is what I understand. 尝试重现您的问题后,这是我的理解。

Probably your Label frame is big, and the default CATextLayer font properties don't fit the frame completely. 您的Label框可能很大,并且默认的CATextLayer字体属性无法完全适合该框。

Try adjusting CATextLayer's properties. 尝试调整CATextLayer的属性。

[intValueLayer setFont:(__bridge CFTypeRef)([UIFont systemFontOfSize:17])];
[intValueLayer setFontSize:17];

so that it matches the properties if you had used label as is. 因此,如果您原样使用了标签,则它与属性匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM