我试着找到这个问题的答案,每次它都假设我知道的太多了。我完全是个初学者。我刚刚创建了一个新的空白应用程序。我把TextView拖到了故事板上。接下来我该怎么做才能给它一个边框呢?
此时,除了默认的、自动生成的代码外,没有其他代码。
发布于 2014-11-14 06:00:39
以下是步骤:如果您让Xcode创建一个项目,请转到ViewController.swift文件。在这里你可以创建一个插座。
@IBOutlet var text : UITextField?现在,您可以将文本出口连接到情节提要中的文本字段。您可以通过选择助理编辑器来执行此操作。然后,控件将一条线从代码中的outlet拖到文本字段中。
连接文本字段后,可以在viewDidLoad函数中添加代码以创建边框。
class ViewController: UIViewController {
@IBOutlet var text : UITextField?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
text!.layer.borderWidth = 1
text!.layer.borderColor = UIColor.redColor().CGColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}发布于 2019-03-21 13:52:55
在Swift 3和Xcode 10中,在(swift 5和code 12)中测试并工作
首先,创建文本视图的出口
在你的视图中放上这两行
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.textView.layer.borderColor = UIColor.lightGray.cgColor
self.textView.layer.borderWidth = 1
}
}https://stackoverflow.com/questions/26917817
复制相似问题