Ios 字体大小和类型不适用于CATextLayer
我试图修改层中文本的字体属性,但没有这样做。有人能帮忙吗?请查找以下代码:Ios 字体大小和类型不适用于CATextLayer,ios,text,fonts,layer,Ios,Text,Fonts,Layer,我试图修改层中文本的字体属性,但没有这样做。有人能帮忙吗?请查找以下代码: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // All HypnosisViews start with a clear background color [self setBackgroundColor:[UIColor clearColor]]; [sel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// All HypnosisViews start with a clear background color
[self setBackgroundColor:[UIColor clearColor]];
[self setCircleColor:[UIColor lightGrayColor]];
// Create the new layer object
boxLayer = [[CATextLayer alloc] init];
// Give it a size
[boxLayer setBounds:CGRectMake(0.0, 0.0, 300.0, 85.0)];
// Give it a location
[boxLayer setPosition:CGPointMake(160.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.75];
// 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 layer] addSublayer:boxLayer];
NSString *text2 = @"You are me.";
UIFont *font2 = [UIFont fontWithName:@"Times New Roman" size:10.0];
[text2 sizeWithFont:font2];
[boxLayer setString:text2];
}
return self;
}
要更改CATextLayer的字体/字体大小,必须为该层的“字体”和“字体大小”属性指定值 或者必须使用NSAttributedString,在这种情况下,将使用该string对象的值 您使用的“sizeWithFont”调用是一个NSString加法,它只计算并返回一个CSSize,该CSSize包含您指定字体中文本的宽度和高度。由于在代码中不使用返回的CGSize,因此它完全不起任何作用
在。完美中的参考-如果这是您正在寻找的,请将此标记为正确答案,以便其他人可以看到此问题已解决!我当然会,但是怎么做呢?我是这个网站的新手。还有关于CATextLayer:有没有办法绕过图层角?如何在图层内为文本换行?我还没有问任何问题:-),但我假设答案下面有一个复选标记,您可以单击它,以验证答案是否正确。您是否查看了CALayer的属性?这将向您展示如何拥有圆角(通过cornerRadius属性)。如果我查看CATextLayer的文档,我会说“wrapped”属性允许您指定在需要时打断文本行。是的,我知道“wrapped”,但它确定文本是否被包装以适合接收者的边界。就像当它到达边缘时,它正在破碎。这很好。我也期待着在文本到达边缘之前,随时打破它。我会继续探索。但是已经感谢你的帮助。