Forum Xamarin.iOS

recommended way to display rich text

jp99jp99 MVMember ✭✭

hi guys,

what is the recommended way to display rich text in an iPhone app?

Do I need to create an HTML file and embed it in a WebView or is there a better way to do that?

thanks in advance,
jp99

Posts

  • sezamuzsezamuz BSMember ✭✭

    use NSMutableAttributedString

    example:
    private void DisplayText()
    {
    var attributedString = new NSMutableAttributedString(Title +Selection);

                var atTitle = new UIStringAttributes {Font = UIFont.BoldSystemFontOfSize(17), ForegroundColor = UIColor.Black};
                attributedString.AddAttributes(atTitle.Dictionary, new NSRange (0, Title.Length));
    
                var atSelection = new UIStringAttributes {Font = UIFont.SystemFontOfSize(16), ForegroundColor = UIColor.FromRGB(127,127,127)};
                attributedString.AddAttributes(atSelection.Dictionary, new NSRange (Title.Length, attributedString.Length - Title.Length));
    
                AttributedText = attributedString;
                Lines = 0;
                this.Frame = new System.Drawing.RectangleF(this.Frame.X, this.Frame.Y, 270,0 );
                SizeToFit ();
            }
    
Sign In or Register to comment.