Nat*_*kle 9 border swift xcode6.1
我已经尝试找到答案,每次假设我知道的方式太多了.我是初学者.我刚刚创建了一个新的空白应用程序.我将TextView拖到故事板上.我接下来要做什么给它一个边框?
此时除了默认的自动生成代码之外没有其他代码.
Ray*_*ond 32
以下是步骤:如果让Xcode创建项目,请转到ViewController.swift文件.在这里你可以创建一个插座.
@IBOutlet var text : UITextField?
Run Code Online (Sandbox Code Playgroud)
现在,您可以将文本插座连接到故事板中的文本字段.您可以通过选择助理编辑器来完成此操作.比控制从代码中的插座拖动一行到文本字段.
连接文本字段后,您可以添加代码以在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.
}
}
Run Code Online (Sandbox Code Playgroud)
在 Swift 3 和 Xcode 10 中,测试并在(swift 5 和代码 12)中工作
首先,创建一个文本视图的出口
并在你的 viewdidload 中放置这两行
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17912 次 |
| 最近记录: |