0

Here is my case I have custom control that inherent from UILable and I need to create method that take image (from code or storyboard) to be added to my label

My tries to convert this code to Xamarin.iOS Source

let attachment = NSTextAttachment()        
attachment.image = UIImage(named: "yourIcon.png")
let attachmentString = NSAttributedString(attachment: attachment)
let myString = NSMutableAttributedString(string: price)
myString.appendAttributedString(attachmentString)
label.attributedText = myString


 public void SetLeftDrawable(UIImage image){

    var attachment = new NSTextAttachment();
    attachment.Image = image;
    var attachmentString = new 
    NSAttributedString(attachment,null);  // this method take string not NSTextAttachment 
  }

any one could help me

Community
  • 1
  • 1
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156

1 Answers1

3

Try this:

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;
}

Hope this helps.-

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
pinedax
  • 9,246
  • 2
  • 23
  • 30