Here is an example of using UIStringAttributes
instead:
string line1 = "Don't have Facebook?", line2 = "\nCreate or sign in with an 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 is an example of setting two different fonts on a UIButton
. Theme
is my own static class, you can replace the color and font with your own.
You should be able to accomplish the same thing with UIStringAttributes
as with CTStringAttributes
. You might post a bug report to Xamarin for your case that crashes: http://bugzilla.xamarin.com
*NOTE: attributed string only works on iOS 6 and higher. This is when Apple added these APIs.