Skip to content

Instantly share code, notes, and snippets.

@smsdm4
Created November 25, 2024 08:44
Show Gist options
  • Save smsdm4/214be7a81b30e34b71e2aa22febb43eb to your computer and use it in GitHub Desktop.
Save smsdm4/214be7a81b30e34b71e2aa22febb43eb to your computer and use it in GitHub Desktop.
prompt-two
import UIKit
class ViewController: UIViewController {
let imageView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
// تنظیم UIImageView
imageView.frame = view.bounds
imageView.contentMode = .scaleAspectFit
view.addSubview(imageView)
// URL تصویر
let urlString = "https://example.com/image.jpg"
if let url = URL(string: urlString) {
downloadImage(from: url)
}
}
func downloadImage(from url: URL) {
// دانلود تصویر
let task = URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data, let image = UIImage(data: data) {
DispatchQueue.main.async {
// نمایش تصویر
self.imageView.image = image
}
} else {
print("خطا در دانلود تصویر: \(error?.localizedDescription ?? "Unknown error")")
}
}
task.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment