swift UIAlertController使用 UIAlertController的宽度 为270

     
添加子控件  
1. 有标题, alert标题高度大概 是 40, 子控件的 Y一般在40 ,如果中间有换行, \n 的高度大概是30 
2.alert的宽度 是270, 设置frame 的时候注意



   /// \n\n\n 多打几行 可以添加 空间高度
        let alert = UIAlertController(title: "预约\n信息\n\n\n", message: "", preferredStyle: UIAlertControllerStyle.alert)
        
        /// 添加输入框
        let textView = UITextView()
        textView.text = self.dataArr[row].remark
        textView.textColor = UIColor.black
        textView.backgroundColor = UIColor.red
        //        textView.delegate = self
        textView.frame = CGRect(x: 10, y: 40 + 30, width: 250 , height: 90)
        alert.view.addSubview(textView)
        
        //添加确定按钮
        alert.addAction(UIAlertAction.init(title: "确定", style: UIAlertActionStyle.default, handler: { (_) in
            DDLOG(message: "点了确定 = \(textView.text)")
        }))
        
        //添加取消按钮
        alert.addAction(UIAlertAction.init(title: "取消", style: UIAlertActionStyle.cancel, handler: { (_) in
            DDLOG(message: "点了取消")
        }))

        self.present(alert, animated: true) {
            DDLOG(message: "添加完成")
        }

  

猜你喜欢

转载自www.cnblogs.com/qingzZ/p/9651600.html