菜鸟教程小白 发表于 2022-12-13 09:33:53

ios - uiimage 的文本字段中的左边距


                                            <p><p>我正在尝试使用 Xamarin iOS 将图像放入 textfied 中,图像确实看起来不错,但我不知道如何在图像左侧放置边距,因为它卡在文本字段的左边缘。下面是代码和结果。我在这里错过了什么?</p>

<pre><code> var imageView = new UIImageView(UIImage.FromBundle(&#34;xyz.png&#34;))
      {
            Frame = new RectangleF(1,1,20,20);
      };
      Tf1.LeftViewMode = UITextFieldViewMode.Always;
      Tf1.LeftView = imageView;
</code></pre>

<p> <img src="/image/b9rxv.png" alt="Result of uiimage"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以执行以下操作,通过创建另一个 <strong>UIView</strong> 并将 <strong>UIImageView</strong> 放置在现有的 <strong>UIView</strong> 中来获得您想要实现的缩进> 带有偏移量,如下例所示:-</p>

<pre><code>var imageView = new UIImageView(UIImage.FromBundle(&#34;xyz.png&#34;))
{
    // Indent it 10 pixels from the left.
    Frame = new RectangleF(10,0,20,20)
};

UIView objLeftView = new UIView(new Rectangle(0,0,30,20));
ojLeftView.AddSubview(imageView);
</code></pre>

<p>然后在 <strong>UITextField</strong> 上设置 <strong>LeftView</strong> 如下:-</p>

<pre><code>objUITextField.LeftViewMode = UITextFieldViewMode.Always;
objUITextField.LeftView = objLeftView;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - uiimage 的文本字段中的左边距,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26288160/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26288160/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - uiimage 的文本字段中的左边距