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

ios - 如何为 textfield-ios 设置两种不同的边框笔触颜色


                                            <p><p>在我们的应用程序中,我们希望在文本字段周围有 2 种不同的边框颜色(例如:一种颜色的上边缘和左边缘,另一种颜色的下边缘和右边缘)
-这可能吗?任何帮助将不胜感激。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><strong>没有预先构建的方式为每个边框边设置不同的颜色</strong>,但<strong>您可以使用图层来伪造它</strong>。可能比它的值(value)更多的工作,但基本上你想要做的是为每个边框绘制单独的 calayers,然后将它们添加到文本字段。</p>

<pre><code>#import &lt;QuartzCore/QuartzCore.h&gt; //This goes up top, but you already know that :-)

CALayer *topBorder = ;
topBorder.frame = // cgrect of where you want the bottom border. Use the textfields frame as reference, but treat the border as a solid rectangle
topBorder.backgroundColor = .CGColor; // the .CGColor is important, don&#39;t forget it

;
</code></pre>

<p>然后只需冲洗并重复每一面。您甚至可以正常设置主色,然后只需添加不同的边(减少工作量)</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何为 textfield-ios 设置两种不同的边框笔触颜色,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15366009/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15366009/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何为 textfield-ios 设置两种不同的边框笔触颜色