Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xamarin ios c# underline UIButton text

I am trying to underline the text in this UIButton ("Privacy Policy"). How can this be accomplished? Here is my code:

var PrivacyPolicy = new UIButton(new CGRect(10, s.MxHt - 40, (s.MxWd - 20) / 3, 30));

PrivacyPolicy.BackgroundColor = UIColor.FromRGB(0, 92, 191);
PrivacyPolicy.Font = UIFont.FromName("Roboto", 14f);
PrivacyPolicy.SetTitle("Privacy Policy", UIControlState.Normal);
PrivacyPolicy.TouchUpInside += HandleBtnOpenPrivacyTouchUpInside;            

if (iPad == false)
{
    PrivacyPolicy.Font = UIFont.SystemFontOfSize(12);
}

View.AddSubview(PrivacyPolicy);
like image 478
Douglas Hill Avatar asked Dec 01 '15 13:12

Douglas Hill


1 Answers

Also, I found this to work as well. Thank you!

        //Set attribute for underlineing information links
        var underlineAttr = new UIStringAttributes { UnderlineStyle = NSUnderlineStyle.Single, ForegroundColor = UIColor.White };

        //Privacy Button Link
        var PrivacyPolicy = new UIButton(new CGRect(10, s.MxHt - 40, (s.MxWd - 20) / 3, 30));
        PrivacyPolicy.BackgroundColor = UIColor.FromRGB(0, 92, 191);
        PrivacyPolicy.Font = UIFont.FromName("Roboto", 14f);            
        PrivacyPolicy.SetAttributedTitle(new NSAttributedString("Privacy Policy", underlineAttr), UIControlState.Normal);
        PrivacyPolicy.TouchUpInside += HandleBtnOpenPrivacyTouchUpInside;            
        if (iPad == false) { PrivacyPolicy.Font = UIFont.SystemFontOfSize(12); }            
        View.AddSubview(PrivacyPolicy);
like image 171
Douglas Hill Avatar answered Sep 22 '22 11:09

Douglas Hill