die Textansicht ist dynamisch, die eine Schaltfläche in der oberen rechten Ecke enthält. es funktioniert für Textfeld. nicht Schaltfläche in Textview zeigt ..Nicht möglich, Schaltfläche oben rechts in UITextView programmgesteuert in Swift
Warten ....
class CommonTextView: UITextView {
private let microphoneButton = UIButton(type: .System)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initTextView()
}
func initTextView() -> Void {
self.layer.cornerRadius = 7
microphoneButton.translatesAutoresizingMaskIntoConstraints = false
//microphoneButton.backgroundColor = UIColor.lightGrayColor().colorWithAlphaComponent(0.3)
microphoneButton.setImage(UIImage(named: "mic"), forState: .Normal)
microphoneButton.tintColor = UIColor.darkGrayColor()
microphoneButton.addTarget(self, action: #selector(self.microphonePressed), forControlEvents: .TouchUpInside)
self.addSubview(microphoneButton)
let trailingConstraint = NSLayoutConstraint(item: microphoneButton, attribute: .Trailing, relatedBy: .Equal, toItem: self, attribute: .Trailing, multiplier: 1, constant: 0)
let topConstraint = NSLayoutConstraint(item: microphoneButton, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1, constant: 0)
let widthConstraint = NSLayoutConstraint(item: microphoneButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 40)
let heightConstraint = NSLayoutConstraint(item: microphoneButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 40)
self.addConstraints([trailingConstraint, topConstraint, widthConstraint, heightConstraint])
}
zeigen Sie Ihren Code bitte –
Ich habe den Code aktualisiert –
Können Sie auf den allgemeinen Ort klicken, wo Ihr Knopf sein sollte? Hat es irgendeinen Effekt? –