【发布时间】:2011-09-04 12:46:18
【问题描述】:
我正在使用 CATextLayer,为了在 iOS 中使用自定义字体,我知道有一种简单的方法可以通过 Fonts provided by application 使用自定义字体,但这是不同的字体。我想知道有没有办法改变每个字符之间的间距?我没有找到任何财产这样做!
已编辑:
- (void)viewWillAppear:(BOOL)animated {
CTFontRef font = [self newCustomFontWithName:@"yeki"
ofType:@"ttf"
attributes:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:16.f]
forKey:(NSString *)kCTFontSizeAttribute]];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
normalTextLayer_ = [[CATextLayer alloc] init];
normalTextLayer_.font = font;
normalTextLayer_.string = str;
normalTextLayer_.wrapped = YES;
normalTextLayer_.foregroundColor = [[UIColor purpleColor] CGColor];
normalTextLayer_.fontSize = 50.f;
normalTextLayer_.alignmentMode = kCAAlignmentRight;
normalTextLayer_.frame = CGRectMake(0.f,100.f, screenBounds.size.width, screenBounds.size.height /1.f);
[self.view.layer addSublayer:normalTextLayer_];
CFRelease(font);
}
【问题讨论】:
-
你是说字距?您可以尝试使用
CGContextSetCharacterSpacing。 -
是的,但我没有为 CATextLayer 类找到
CGContextSetCharacterSpacing的任何解决方案!
标签: iphone ios core-animation catextlayer