Mc.*_*ver 8 iphone core-animation ios catextlayer
我正在使用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);
}
Run Code Online (Sandbox Code Playgroud)
omz*_*omz 12
您可以为图层指定NSAttributedString(或NSMutableAttributedString)而不是plain NSString,并使用该kCTKernAttributeName属性(请参阅核心文本字符串属性参考)来调整字距.
例:
CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica"), 30, NULL);
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
(id)font, kCTFontAttributeName,
[NSNumber numberWithFloat:15.0], kCTKernAttributeName,
(id)[[UIColor greenColor] CGColor], kCTForegroundColorAttributeName, nil];
NSAttributedString *attributedString = [[[NSAttributedString alloc] initWithString:@"Hello World" attributes:attributes] autorelease];
CFRelease(font);
myTextLayer.string = attributedString;
Run Code Online (Sandbox Code Playgroud)
这应该会在Helvetica 30中为您提供增加字符间距的绿色文本.
| 归档时间: |
|
| 查看次数: |
3639 次 |
| 最近记录: |