UILabelに画像とテキストをつけて作っています。私は以下のように多くのことを試しています。このコードUILabel画像とテキストがiOS(Xamarin)
var textAttchment = new NSTextAttachment();
textAttchment.Image = UIImage.FromBundle("location_grey_icon");
var attachmentString = NSAttributedString.FromAttachment(textAttchment);
var attributedString = new NSMutableAttributedString(lbl_inr.Text.ToString());
this.lbl_inr.AttributedText = attributedString;
を使用して
しかし、それだけで、テキストではない画像が表示されます
は1を試してみてください。
は2を試してみてください。このコード
var attchment = new NSTextAttachment();
attchment.Image = UIImage.FromBundle("location_grey_icon");
attchment.Bounds = new CGRect(0, -1, 13, 13);
var intiliazeText = this.text_inr.AttributedText;
var newText = new NSMutableAttributedString(intiliazeText);
newText.Append(NSAttributedString.CreateFrom(attchment));
this.text_inr.AttributedText = newText;
を使用して
それは画像とテキストの両方を表示しています。
出力:私が欲しいもの
:
が、私はテキストので、第1の画像と[テキストの前に画像を設定したいと私の要件があります。
助けてください。
を感謝しかし、私はとにかく1 'UILabel'が、おかげでこれをやりたいです。 – Ironman
私の答えを見る私は1つの 'UILabel'を使ってそれを実行しています。 – Ironman
@アイロンマンあなたが言ったとき "私の要件はテキストの前にイメージを設定して、最初のイメージとテキストを設定したいということです。"私は別の何かを理解した。あなたは道を見つけました。 – apineda