在Reddit应用程序中创建保存/未保存的帖子确认模式?

问题描述 投票:0回答:1

在Reddit应用程序上创建小弹出/模态的最佳方法是什么(请参阅下面的链接获取图片)?我尝试过使用UIAlertView,但它不是很容易定制的。任何帮助/指导将不胜感激!

Screenshot of Reddit app's save "Post Saved!" confirmation modal

swift
1个回答
0
投票

尝试像这样的东西

extension UIViewController
{
    func showNotificationView(message : String)
    {
        //base View
        let baseView = UIView(frame: CGRect(x: 20, y: self.view.frame.size.height-(self.view.frame.size.height*0.15), width: self.view.frame.size.width-40, height: self.view.frame.size.height*0.08))
        baseView.backgroundColor = UIColor.gray
        baseView.clipsToBounds=true
        self.view.addSubview(baseView)

        //Image View
        let imageView = UIImageView(image: UIImage(named: "RM_3"))
        imageView.clipsToBounds=true
        imageView.frame = CGRect(x: 0, y: 0, width: baseView.frame.size.width*0.2, height: baseView.frame.size.height)
        baseView.addSubview(imageView)

        //Label
        let textLabel = UILabel(frame: CGRect(x: baseView.frame.size.width*0.2+10, y: 0, width: baseView.frame.size.width, height: baseView.frame.size.height))
        textLabel.textColor = UIColor.white
        textLabel.backgroundColor = UIColor.clear
        textLabel.textAlignment = .left;
        textLabel.numberOfLines = 0
        textLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
        textLabel.text = message
        baseView.addSubview(textLabel)
    }
}

如何使用

 @IBAction func navigate(_ sender: Any) {
        self.showNotificationView(message: "hihihihh")
    }

产量

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.