具有属性的Monotouch自定义字体

时间:2012-01-25 18:19:51

标签: c# fonts xamarin.ios core-text

如何在monotouch中指定字体粗体/斜体等属性?

实际上可以在本地库中使用 http://www.freetimestudios.com/2010/09/20/ipad-and-ios-4-custom-font-loading/

NSDictionary *fontAttributes =
  [NSDictionary dictionaryWithObjectsAndKeys:
    @"Courier", (NSString *)kCTFontFamilyNameAttribute,
    @"Bold", (NSString *)kCTFontStyleNameAttribute,
    [NSNumber numberWithFloat:16.f], (NSString *)kCTFontSizeAttribute,
    nil];
CTFontDescriptorRef descriptor =
  CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes);
CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, 0, NULL);
CFRelease(descriptor);

1 个答案:

答案 0 :(得分:2)

与您的代码段匹配的MonoTouch / C#代码如下所示:

CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes () {
    FamilyName = "Courier",
    StyleName = "Bold",
    Size = 16.0f
};
CTFontDescriptor fd = new CTFontDescriptor (fda);
CTFont font = new CTFont (fd, 0);