默认情况下,UITextField的边框 colored颜色 为浅灰色.

我试过:

myTextView.layer.borderColor = UIColor.lightGrayColor().CGColor
// or
myTextView.layer.borderColor = UIColor.lightTextColor().CGColor
// or 
myTextView.layer.borderColor = myTextField.layer.borderColor

它们还有很多不同的 colored颜色 .

如何设置UITextView边框以匹配UITextField colored颜色 ?

推荐答案

试试这个代码.

UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0];

myTextView.layer.borderColor = borderColor.CGColor;
myTextView.layer.borderWidth = 1.0;
myTextView.layer.cornerRadius = 5.0;

更改"borderWidth"和"cornerRadius"值,以获得UITextField的准确用户界面.

Swift相关问答推荐

纹理资源加载问题(图像解码失败)

SwiftData:线程1:&Quot;NSFetchRequest找不到实体名称';提醒&q;的NSEntityDescription

NavigationLink和ObservableObject的动画片段

为什么我不能在这个 Swift 间接枚举中返回 self ?

如何从 RC 加载场景作为 ModelEntity 而不是普通实体?

deinitialize() 与 deallocate()

如何在类中打印函数

为什么 id 不能通过 struct 从 Objective-C 移植到 Swift?

SwiftUI:调用以编程方式创建的视图的函数

展开 List 中的 HStack 以端到端但不是从上到下,因此看起来项目之间有更宽的空间

为什么swiftui中的导航视图栏那么大?

Swift中的分段错误

Swift 2 中的新 @convention(c):我该如何使用它?

我可以在 Swift 中为泛型类型 T 分配默认类型吗?

如何从 Swift 中的字符串生成条形码?

如何使用 swift 将 Images.xcassets 中的图像加载到 UIImage 中

在 Swift 中以编程方式更新约束的常量属性?

URLComponents.url 为零

如何在 Swift 中判断变量的类型

Swift 5 秒后关闭 UIAlertView