【问题标题】:Monotouch Custom Font with Attributes带有属性的 Monotouch 自定义字体
【发布时间】:2012-01-25 18:19:51
【问题描述】:

如何在 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);

【问题讨论】:

  • 其他问题 (stackoverflow.com/questions/4913363/…) 有帮助吗?
  • 实际上对我没有帮助。我需要自定义字体的粗体文本
  • 您是否阅读了您之前列出的链接上的“使用 iOS 注册自定义字体”部分,并验证了 Info.plist 中的 UIAppFonts 是否正确设置了所有内容?

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


【解决方案1】:

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

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

【讨论】:

  • 非常感谢,但这里有一个新问题。我如何与 uilabel/uibutton 等一起使用。我如何将 ctfont 转换为 uifont
  • 请参阅stackoverflow.com/questions/6714858/…,但请注意并非所有属性都会被转换。但是,这将涵盖 Bold。在 C# 中,这应该看起来像 UIFont f = UIFont.FromName (font.PostScriptName, 16);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-17
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 2011-06-22
相关资源
最近更新 更多