Xamarin.iOS将左图像添加到UILable

时间:2017-05-14 13:00:05

标签: xamarin.ios uilabel

这是我的情况,我有UILable固有的自定义控件 我需要创建拍摄图像的方法(来自代码或故事板) 要添加到我的标签

我尝试将此代码转换为Xamarin.iOS Source

<button id="movies">Movies</button>
<button id="animals">Animals</button>

任何人都可以帮助我

1 个答案:

答案 0 :(得分:2)

试试这个:

public void SetLeftDrawable (UIImage image)
{
    var attachment = new NSTextAttachment ();
    attachment.Image = image;
    var attachmentString = NSAttributedString.FromAttachment (attachment);
    //replace "price" with your string.
    var myString = new NSMutableAttributedString ("price");
    myString.Append (attachmentString);
    AttributedText = myString;
}

希望这会有所帮助.-