OGeek|极客世界-中国程序员成长平台

标题: ios - 如何为 textfield-ios 设置两种不同的边框笔触颜色 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:33
标题: ios - 如何为 textfield-ios 设置两种不同的边框笔触颜色

在我们的应用程序中,我们希望在文本字段周围有 2 种不同的边框颜色(例如:一种颜色的上边缘和左边缘,另一种颜色的下边缘和右边缘) -这可能吗?任何帮助将不胜感激。



Best Answer-推荐答案


没有预先构建的方式为每个边框边设置不同的颜色,但您可以使用图层来伪造它。可能比它的值(value)更多的工作,但基本上你想要做的是为每个边框绘制单独的 calayers,然后将它们添加到文本字段。

#import <QuartzCore/QuartzCore.h> //This goes up top, but you already know that :-)

CALayer *topBorder = [CALayer layer];
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 = [UIColor greenColor].CGColor; // the .CGColor is important, don't forget it

[toScrollView.layer addSublayer:topBorder];

然后只需冲洗并重复每一面。您甚至可以正常设置主色,然后只需添加不同的边(减少工作量)

关于ios - 如何为 textfield-ios 设置两种不同的边框笔触颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15366009/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4