2
votes

How can i specify font bold/italic etc. properties in monotouch?

Actually possible in native library 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
Does this other question (stackoverflow.com/questions/4913363/…) help at all? - summea
actually not helped for me. i need a bold text for custom fonts - Mesut A.
Have you read through the "Registering Custom Fonts With iOS" section on that link you listed earlier and verified that everything is correctly set with UIAppFonts in the Info.plist? - summea

1 Answers

2
votes

The MonoTouch / C# code to match your code snippet would look like this:

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