how to add hyphen when using CharacterWrap

Dhruv Gohil 1 Reputation point
2021-03-10T04:27:13.08+00:00

How can I add hyphen at the end when character wraps in label
(e.g. Iabel has word called "donation")

currently it wraps like,
donati
on

I want it to be wrapped using hyphen, like
donati-
on

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-03-10T09:26:33.313+00:00

    Hello,

    Welcome to Microsoft Q&A!

    This could be achieved with custom renderer .

    For example

    iOS Solution
       [assembly: ExportRenderer(typeof(Label), typeof(MyLabelRenderer))]  
       namespace FormsA.iOS  
       {  
           public class MyLabelRenderer : LabelRenderer  
           {  
               protected override void OnElementChanged(ElementChangedEventArgs<Label> e)  
               {  
                   base.OnElementChanged(e);  
         
                   if (Control != null)  
                   {  
                       string content = Control.Text;  
         
                       NSMutableAttributedString attributedString = new NSMutableAttributedString(content);  
         
                       NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();  
                       paragraphStyle.HyphenationFactor = 1.0f;  
         
                       attributedString.AddAttribute(UIStringAttributeKey.ParagraphStyle, paragraphStyle, new NSRange(0, content.Length));  
         
                       Control.AttributedText = attributedString;  
                   }  
               }  
         
           }  
       }  
    

    Refer to https://stackoverflow.com/a/19414663/8187800 .


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments