ios - CTFont with CTStringAttributes and NSMutableAttributedString crashes my app in xamarin -


i'm trying create nsmutableattributedstring , set properties setproperties method. app crashes error,

monotouch.foundation.monotouchexception exception - nsinvalidargumentexception reason: unrecognized selector sent instance 0xc305d00.* 

code:

var richtask = new nsmutableattributedstring ("random"); var fda = new ctfontdescriptorattributes {     familyname = "courier",     stylename = "bold",     size = 18f }; var fd = new ctfontdescriptor (fda); var font = new ctfont (fd, 0);  var attrs = new ctstringattributes { font = font }; var range = new nsrange (0, 3); richtask.setattributes(attrs, range);  _label.attributedtext = richtask; 

this code in getcell method of uitableviewcontroller. want able change font or color of first 3-4 letters of string.

i figured out if eliminate font component , set property, example, strokewidth, works fine

var attrs = new ctstringattributes { /*font = font*/ strokewidth = 5f }; 

so seems font initialized incorrect. why that? why crash app?

thanks advance!

here example of using uistringattributes instead:

        string line1 = "don't have facebook?", line2 = "\ncreate or sign in alternate account";         var attributedstring = new nsmutableattributedstring(line1 + line2);          attributedstring.setattributes(new uistringattributes         {             font = theme.boldsmallfont,             foregroundcolor = theme.lightgray,          }.dictionary, new nsrange(0, line1.length));          attributedstring.setattributes(new uistringattributes         {             font = theme.regularsmallfont,             foregroundcolor = theme.lightgray,          }.dictionary, new nsrange(line1.length, line2.length));          _alternatesignin.setattributedtitle(attributedstring, uicontrolstate.normal); 

this example of setting 2 different fonts on uibutton. theme own static class, can replace color , font own.

you should able accomplish same thing uistringattributes ctstringattributes. might post bug report xamarin case crashes: http://bugzilla.xamarin.com

*note: attributed string works on ios 6 , higher. when apple added these apis.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -