urbn/URBNAlert

UITextView Support

Opened this issue · 1 comments

Cannot get UITextView to work as a custom view

Have tried using UITextView as the custom view itself and also adding the UITextView to another view and adding constraints

Need a solution to multiline input

I did a hack to achieve this. I use a UILabel to handle the sizing and add a textView on top of it

 let view = UIView()
        
        let lbl = UILabel()
        lbl.numberOfLines = 4
        lbl.text = "1\n2\n3\n4"
        lbl.isHidden = true
        lbl.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(lbl)
        
        let txtView = UITextView()
        txtView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(txtView)
        
        let bindings = ["lbl": lbl, "txtView": txtView] as [String : Any]
        
        
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[lbl]|", options: [], metrics: nil, views: bindings))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[lbl]|", options: [], metrics: nil, views: bindings))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[txtView]|", options: [], metrics: nil, views: bindings))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[txtView]|", options: [], metrics: nil, views: bindings))
        
        let alertController = URBNAlertViewController(title: nil, message: nil, view: view)!
        alertController.alertStyler.firstResponder = txtView

Part 2 I had a problem with the firstResponder not moving the keyboard up when the view was presented. So I forked the project and call becomeFirstResponder in the complete block instead of immediately in viewDidAppear:


- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    // Added this check so if you presented a modal via a passive alert then
    //   dismissed that modal, another alert is not added to the view if the alert
    //   did not finish dismissing yet
    if (!self.viewControllerVisible) {
        
        
         __weak typeof(self) weakSelf = self;
        [self setVisible:YES animated:YES completion:^(URBNAlertViewController *alertVC, BOOL finished) {
        
        
        if (weakSelf.alertStyler.firstResponder) {
            [weakSelf.alertStyler.firstResponder becomeFirstResponder];
        }
        
 
    }];
        
        //[self setVisible:YES animated:YES completion:nil];
    }
    
    self.viewControllerVisible = YES;
    
    
}