随笔 - 400,  文章 - 0,  评论 - 7,  阅读 - 21万
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
添加子控件 
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: "添加完成")
        }

  

 

 

 

2. 自定义文字大小颜色等

 

 

复制代码
 private func showTipAlert(tipStr:String,
                              leftStr:String,
                              leftColor:UIColor,
                              leftBlock:(()->())?,
                              rightStr:String,
                              rightColor:UIColor,
                              rightBlock:(()->())?){
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertController.Style.alert)
        
        //修改title
        let alertTitle = NSMutableAttributedString(string: tipStr, attributes: [NSAttributedString.Key.foregroundColor :  UIColor.init(hexString: "#424242") ,NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14)])
       
        alert.setValue(alertTitle, forKey: "attributedTitle")
        
        /// 左边的按钮
        let leftAction = UIAlertAction(title: leftStr, style: UIAlertAction.Style.default) { (_) in
            leftBlock?()
        }
        leftAction.setValue(leftColor, forKey: "titleTextColor")
        alert.addAction(leftAction)
        
        /// 右边的按钮
        let rightAction = UIAlertAction(title: rightStr, style: UIAlertAction.Style.default, handler: { (_) in
            rightBlock?()
        })
        rightAction.setValue(rightColor, forKey: "titleTextColor")
        alert.addAction(rightAction)
        self.present(alert, animated: true, completion: nil)
    }
复制代码

 

添加 自定义view参考 

Swift - 自定义UIAlertController的样式2(添加自定义视图):https://www.hangge.com/blog/cache/detail_1657.html

posted on   懂事长qingzZ  阅读(888)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示