gpt4 book ai didi

ios - UITextField 只有顶部和底部边框

转载 作者:IT王子 更新时间:2023-10-29 07:53:10 25 4
gpt4 key购买 nike

我目前有一个常规边框。我想只有顶部和底部边框

我该如何实现?

使用 UITextFieldlayer 属性,我有以下代码:

    self.layer.borderColor = [[UIColor colorWithRed:160/255.0f green:160/255.0f blue:160/255.0f alpha:1.0f] CGColor];
self.layer.borderWidth = 4.0f;

我已经通过使我的 UITextField 加长 来让它工作了,这样用户就看不到左右边框了,但我只是想知道是否有更好的、更少的这样做的骇人听闻的方式?

我已经检查了文档,更改UITextFieldborderStyle 没有这个选项。

来自,

iOS 初学者

最佳答案

我发现一种很有效的方法是使用图层。这是一个片段:

CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.frame.size.width, 1.0f);
bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
[myTextField.layer addSublayer:bottomBorder];

希望这对某人有帮助。

关于ios - UITextField 只有顶部和底部边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15562438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com