UITextField仅顶部和底部边框 [英] UITextField Only Top And Bottom Border

查看:280
本文介绍了UITextField仅顶部和底部边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有常规边境.我想仅具有顶部和底部边框.

I currently have a regular border. I would like to only have a top and bottom border.

我如何做到这一点?

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

Using the UITextField's layer property, I have the following code:

    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变长,我可以使它工作,以便用户看不到左右边框,但是我只是想知道是否有更好,更少的边框骇人听闻的方法吗?

I have kind of got it to work by making my UITextField extra long, so that the user does not see the left and right borders, but I was just wondering if there was a better, less hackish way of doing this?

我已经检查了文档,并且更改UITextFieldborderStyle没有此选项.

I have checked the docs, and changing a UITextField's borderStyle does not have this option.

发件人

iOS First Timer

An iOS First Timer

推荐答案

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

One approach I have found works good is using layers. Here's a snippet:

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];

希望这对某人有帮助.

这篇关于UITextField仅顶部和底部边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆