UIStringAttributeKey - all fields are null on iOS 5.1.1

DanielHilgarthDanielHilgarth DEMember
edited February 2013 in Xamarin.iOS

My App should support iOS 5 and up.
When executing my App on iOS 5.1.1 it crashes when creating an attributed string with a font:

new NSAttributedString("foo", UIFont.SystemFontOfSize);

The problem is that the constructor internally uses UIStringAttributeKey.Font to add the font to a dictionary. However, that field - along with all others on that class - is null.

I currently can only test on iOS 5.1.1, so I can't say anything about newer versions.

Is this a know problem?

The workaround is to supply the dictionary myself and use CTStringAttributeKey instead:

var attributes = new NSMutableDictionary();
attributes.Add(CTStringAttributeKey.Font, UIFont.SystemFontOfSize(15));
var attributedString = new NSAttributedString("foo", attributes);

Unfortunately, this doesn't bring me much further. When passing that attributed string to a CTTypesetter I get a SIGSEGV.

Code:

var typeSetter = new CTTypesetter(attributedString);

Exception:

Stack trace:

at MonoTouch.CoreText.CTTypesetter..ctor (MonoTouch.Foundation.NSAttributedString) [0x00018] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreText/CTTypesetter.cs:146
at My code...

Native stack trace:

0   RecsonAppsApple                     0x00797659 mono_handle_native_sigsegv + 244
1   RecsonAppsApple                     0x0075dca9 mono_sigsegv_signal_handler + 172
2   libsystem_c.dylib                   0x353187ed _sigtramp + 48
3   CoreFoundation                      0x3117b405 -[NSObject retain] + 36
4   CoreText                            0x37a7fec5 _ZN11TAttributesC1EPK14__CFDictionary + 12
5   CoreText                            0x37a7f2c1 _ZN21TTypesetterAttrString10InitializeEPK20__CFAttributedString + 204
6   CoreText                            0x37a7f11d _ZN21TTypesetterAttrStringC2EPK20__CFAttributedString + 136
7   CoreText                            0x37a7f091 _ZN21TTypesetterAttrStringC1EPK20__CFAttributedString + 12
8   CoreText                            0x37a97439 CTTypesetterCreateWithAttributedString + 60
9   RecsonAppsApple                     0x0004ce04 wrapper_managed_to_native_MonoTouch_CoreText_CTTypesetter_CTTypesetterCreateWithAttributedString_intptr + 60

Besides not using any attributes, I couldn't find a workaround for this issue.

Sign In or Register to comment.