I have a requirment to use a custom renderer to set an Editor to some rtf text. This all works fine. However, what I am not getting at is how to set or change the font size of this NSAttributedString. The constructors dont seem to allow to hand over any additional attributes like font size etc. On the other hand - the NSMutableAttributedString does not offer to add the NSAttributedStringDocumentAttributes . Maybe I am missing something.
var rtfstring = new NSAttributedString(rtftext, new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.RTF }, ref error);
_uITextView.AttributedText = rtfstring;
SetNativeControl(_uITextView);
Answers
You could convert
NSAttributedString
toNSMutableAttributedString
, and then set the font attribute .If you want to set font size from
Forms project
, you could create a new subclass and create custom renderer for the new custom class .Custom Class
Xaml
Custom Renderer
Xamarin forums are migrating to a new home on Microsoft Q&A!
We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
For more information, please refer to this sticky post.
Thx this helped a lot., Unfortunatley the NSRange part throws an nsrange exception 'mutable.SetAttributes(uiString, new NSRange(0, rtftext.Length));'
NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds.
As the length is 768 this should not be an issue. I could not find any other hint what could cause this exception. I tried already rtftext.Length-1 in case this would be an array index issue - but without luck.
Hi , what is the value of
rtftext
on your side ? Could you debug and post the value here ?