如何在Xamarin iOS

时间:2018-05-14 14:36:42

标签: ios xamarin

我想强调xamarin iOS中的按钮文本,我有一个名为

的样式
    public static UIButton StyleLinkButtonBlack(this UIButton button)
    {
        button.Font = Styles.SetOpenSansSemiboldFont(Dimensions.medium);
        button.LineBreakMode = UILineBreakMode.WordWrap;
        button.SetTitleColor(UIColor.Black, UIControlState.Normal);     
        button.TitleLabel.TextAlignment = UITextAlignment.Center;

        return button;
    }

我如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

只需要添加一个NSMutableAttributedString,就像那样

var attrString = new NSMutableAttributedString(button.TitleLabel.Text);
attrString.AddAttribute(UIStringAttributeKey.UnderlineStyle,NSNumber.FromInt32((int)NSUnderlineStyle.Single),new NSRange(0, attrString.Length));
button.TitleLabel.AttributedText = attrString;