Tag: catextlayer

CATextLayer textcolor始终是黑色的

我正在尝试添加一个CATextLayer到UITableViewCell 。 问题是,当我已经设置了它的foregroundColor时,文本呈现为黑色。 有人能告诉我我失踪了吗? 谢谢。 CATextLayer *buyPrice_port = [CATextLayer layer]; buyPrice_port.frame = CGRectMake(144, 42, 76, 21); buyPrice_port.font = (__bridge CFTypeRef)([UIFont boldSystemFontOfSize:18]); buyPrice_port.foregroundColor = [UIColor colorWithRed:0 green:190/255.0 blue:191/255.0 alpha:1.0].CGColor; buyPrice_port.alignmentMode = kCAAlignmentCenter; buyPrice_port.string = @"BAC"; [self.contentView.layer addSublayer:buyPrice_port];

如何在Swift中更改CATextLayer中的文本颜色

我想改变一个CATextLayer的文字颜色。 这不起作用 myTextLayer.textColor 因为没有这样的财产。 我也没有通过设置前景颜色的反应 textLayer.foregroundColor = someColor.CGColor 当文本层设置如下 let myAttribute = [ NSFontAttributeName: UIFont(name: mongolFontName, size: fontSize )! ] let attrString = NSMutableAttributedString(string: textLayer.displayString, attributes: myAttribute ) textLayer.frame = myFrame textLayer.string = attrString 我已经看到了Objective-C的问题CATextLayer textcolor总是黑色的,但是那里的答案在我的情况下似乎没有意义。 由于我通过阅读文档能够解决我的问题,因此我在下面分享了答案。

CATextLayer + NSAttributtedString + CTParagraphStyleRef

我想有一些自定义的行间距的文本,所以我写了一个CTParagraphStyleAttributte的属性string,并将其传递给我的CATextLayer : UIFont *font = [UIFont systemFontOfSize:20]; CTFontRef ctFont = CTFontCreateWithName((CFStringRef)font.fontName, font.pointSize, NULL); CGColorRef cgColor = [UIColor whiteColor].CGColor; CGFloat leading = 25.0; CTTextAlignment alignment = kCTRightTextAlignment; // just for test purposes const CTParagraphStyleSetting styleSettings[] = { {kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof(CGFloat), &leading}, {kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment} }; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(styleSettings, 2)); NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: (id)ctFont, (id)kCTFontAttributeName, […]