Created
November 25, 2024 08:44
-
-
Save smsdm4/214be7a81b30e34b71e2aa22febb43eb to your computer and use it in GitHub Desktop.
prompt-two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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