xcode 如何在目标 c 中更改文本字段边框样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8906414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:01:45  来源:igfitidea点击:

How to change textfield border style in objective c?

objective-ciosxcodeuitextfieldborder-color

提问by Hacer sengul Akac

I want to change only bottom border style. Is it possible? I know this code

我只想更改底部边框样式。是否可以?我知道这个代码

theTextFiels.layer.borderColor=[[UIColor blueColor]CGColor]; // border rengi
theTextFiels.layer.borderWidth= 5.0f; // border kal?nl???

but this apply the changes to all borders (up, right, left, bottom) How can I change the only bottom border color?

但这将更改应用于所有边框(上、右、左、下) 如何更改唯一的底部边框颜色?

回答by Shubhank

you won't be able to change only one side border color unless you subclass and know you way around in draw rect method of UIView.

除非您子类化并了解 UIView 的 draw rect 方法,否则您将无法仅更改一侧边框颜色。

You should try @stiles way ..making a image and then setting it as background...

您应该尝试@stiles 方式..制作图像,然后将其设置为背景...

Steps are : Make four images ; each with a different side as a color border you want. Then change the text field background to the appropriate one.

步骤是: 制作四个图像;每个都有不同的一面作为您想要的颜色边框。然后将文本字段背景更改为适当的背景。

You should make the images as similar as to original text field ..this way you can achieve what your want,

您应该使图像与原始文本字段相似..这样您就可以实现您想要的,

回答by StilesCrisis

You can do it using an image.

您可以使用图像来完成。

myTextField.background = [UIImage imageNamed:@"blue-line.png"];

myTextField.background = [UIImage imageNamed:@"blue-line.png"];