Как я могу импортировать эту фотографию из UITableView (с помощью UIButton) в UITableView в библиотеку фотографий в Swift? - PullRequest
0 голосов
/ 06 апреля 2020

Я попробую посмотреть подсказку, как загрузить эти обои из приложения в библиотеку фотографий.

Здесь все просто.

Вы должны создать папку Cells с именем ImageTableViewCell

class ImageTableViewCell: UITableViewCell {

    @IBOutlet weak var ImageCells: UIImageView!
    @IBOutlet weak var TitleCells: UILabel!
    @IBOutlet weak var CreditCells: UILabel!
    @IBOutlet weak var ImportViewBackground: UIView!

    // Import the wallpaper to photo library with UIButton
    @IBOutlet weak var ImportCells: UIButton!

    @IBOutlet weak var importLBL: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

Теперь откройте View Controller. Я уже написал код префекта, но я должен дать вам подсказку о кнопках импорта только в UITableViewController.

class ViewController: UIViewController {

    @IBOutlet weak var UITableView: UITableView!

    let titleLbl = ["iOS Wallpaper", "iPadOS Wallpaper", "iOS Wallpaper"]
    let creditlbl = ["@AR72014", "@Apple", "@EvgeniyZemelko"]
    let image = ["Image", "Image-2", "Image-1"]


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        self.navigationItem.title = "Wallpaper"

    }


}


extension ViewController: UITableViewDataSource, UITableViewDelegate {

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        return 400

    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleLbl.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


         let imageTableView = UITableView.dequeueReusableCell(withIdentifier: "Image", for: indexPath) as? ImageTableViewCell

        // Image
        imageTableView?.ImageCells.image = UIImage(named: image[indexPath.row])

        // Title
        imageTableView?.TitleCells.text = titleLbl[indexPath.row]

        // Credit
        imageTableView?.CreditCells.text = "By: \(creditlbl[indexPath.row])"



        // SF Symbol
        let imageAttachment = NSTextAttachment()
        imageAttachment.image = UIImage(systemName: "square.and.arrow.down")?.withTintColor(.white)


        let fullString = NSMutableAttributedString(string: "")
        fullString.append(NSAttributedString(attachment: imageAttachment))
        fullString.append(NSAttributedString(string: " Import"))
        imageTableView?.importLBL.attributedText = fullString

        // Import Image with UIButton
        /// **How should I upload the code to import it from click in the @objc func clicked (_ btn: UIButton)? Thank you!**

        // UIView Background 
        imageTableView?.ImportViewBackground.layer.cornerRadius = 5

        imageTableView?.ImportViewBackground.layer.masksToBounds = true




        return imageTableView!

    }


    @objc func clicked (_ btn: UIButton) {

    // Tap that button will appear the alert to upload the photo library 


    }


}

Вот и все. Есть куча ответов о загрузке из библиотеки фотографий в UITableViewController, поэтому я не хочу этого делать. Я просто ищу «UITableViewController to Photo Library» вот так.

Спасибо за помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...