ios - 如何在 IOS Xcode 中为文本字段设置边框底部?

标签 ios swift xcode

<分区>

我是 IOS Xcode 的新手。我正在构建一个登录页面,因为我希望 textField 应该只显示边框底部, Storyboard应该有一个自定义的渐变背景颜色。我引用了很多网站,但没有得到正确的结果。如何获取,求助!

最佳答案

这是答案,您可以将图层添加到您的文本字段中。 只需使用以下代码即可。

in below code , txtField means your textField in which you want to add the border.

let borderLayer = CALayer()
borderLayer.backgroundColor = color.cgColor

// origin y should be height - 1
borderLayer.frame = CGRect(origin: CGPoint(x: 0.0, y: (txtField.frame.size.height - 1), size: CGSize(width: txtField.frame.size.width, height: 1.0))

txtField.layer.addSublayer(borderLayer)

关于ios - 如何在 IOS Xcode 中为文本字段设置边框底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48317103/

相关文章:

ios - 当用户无法向 Twitter 发送消息时我该怎么办

swift - a 和 b 之和减去 c 是多少?

swift - 用户可以从您的 Xcode 项目访问哪些文件/数据 - Swift 4

ios - 根据条件更改 CollectionView 中选定单元格的颜色

ios - 如何在控制中心显示 "live"(swift iOS)

iphone - 如何对单击的 ImageView 执行一些操作?

ios - 将类中的字符串元素附加到字符串数组

swift - 带有参数和 header 的 Alamofire 多部分形式图像上传 - Swift

xcode - 初始化器 'init(_:)' 要求 'Decimal' 符合 'BinaryInteger'

swift - 更新框架 xcode8 后构建错误