Create a gist now

Instantly share code, notes, and snippets.

Embed
ImageView Kaynak Olarak Url ile Fotoğraf Gösterme | Swift --- http://www.bulentsiyah.com/imageview-kaynak-olarak-url-ile-fotograf-gosterme-swift/
//
// FotografViewController.swift
// Bildir-Basic
//
// Created by Bülent Siyah on 15.05.2018.
// Copyright © 2018 Bülent Siyah. All rights reserved.
//
import UIKit
import Alamofire
class FotografViewController: UIViewController {
@IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.backBarButtonItem?.title = "Geri"
self.title = "Fotoğraf Detayı"
let URL_IMAGE = URL(string: StaticObject.imageSrcBaseUrl + StaticObject.detayNotificationn.UID!)
// Use Alamofire to download the image
Alamofire.request(URL_IMAGE!).responseData { (response) in
if response.error == nil {
print(response.result)
if let data = response.data {
self.image.image = UIImage(data: data)
}
}
}
/*
//image.imageFromUrl("https://robohash.org/123.png")
let session = URLSession(configuration: .default)
//creating a dataTask
let getImageFromUrl = session.dataTask(with: URL_IMAGE!) { (data, response, error) in
//if there is any error
if let e = error {
//displaying the message
print("Error Occurred: \(e)")
} else {
//in case of now error, checking wheather the response is nil or not
if (response as? HTTPURLResponse) != nil {
//checking if the response contains an image
if let imageData = data {
//getting the image
let image = UIImage(data: imageData)
//displaying the image
self.image.image = image
} else {
print("Image file is currupted")
}
} else {
print("No response from server")
}
}
}
//starting the download task
getImageFromUrl.resume() */
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = false
self.navigationController?.navigationBar.topItem!.largeTitleDisplayMode = .never
self.navigationItem.largeTitleDisplayMode = .always
} else {
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment