我用随机标签和文本创建了UITextView
,但是它是用一个变量创建的,是否可以在创建UITextView
之后更新变量(通过单击添加按钮)?也许给它添加一个随机数,例如newText1,newText2 ..等等。
以便下一个UITextView
已经使用新变量创建了?
P.S抱歉,如果这个问题很傻,我最近才开始研究Swift
@IBOutlet weak var addTextButton: UIButton!
@IBOutlet weak var StoriesView: UIView!
var newText = UITextView()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func addTextButton(_ sender: Any) {
let maxNumber = 10000
let i = Int(arc4random_uniform(UInt32(maxNumber)))
newText = UITextView(frame: CGRect(x: self.StoriesView.frame.origin.x + 40, y: self.StoriesView.frame.origin.y + 40, width: 380, height: 80))
self.StoriesView.addSubview(newText)
newText.font = UIFont(name: "Verdana", size: 11)
newText.text = "TAP TO EDIT #\(i)"
newText.sizeToFit()
newText.textColor = UIColor.black
newText.backgroundColor = UIColor.clear
newText.tag = i
newText.isEditable = true
newText.isSelectable = true
newText.isUserInteractionEnabled = true
newText.allowsEditingTextAttributes = true
newText.translatesAutoresizingMaskIntoConstraints = true
newText.enablesReturnKeyAutomatically = true
newText.delegate = self
}
我用随机标签和文本创建了UITextView,但是它是用一个变量创建的,是否可以在创建UITextView之后通过单击添加按钮来更新变量?也许添加一个随机的...
单击按钮时,创建一个新的texView并为其分配标签值。添加后,将i的值更新为+1,以便添加的每个textView都有一个新的标记值。