Scale Factor
In iOS we have to set the images on different kind of devices such as iPhone 4, 5,6 etc. each phone has high scale factor due to that reason images , display in sharp and clear. for that we need to find out scale factor of phone.
there is some condition for setting images
1: we make request to server for getting images.
2: we directly fetch the images from url.
1: if we are making request to server for images then we have to send the request in this way:
1 2 |
let width = String(format:"%f", SCREEN_WIDTH * UIScreen.main.scale); post .appendFormat("width=%@", width); |
note: we multiply the screen width of phone to scale factor.
2: we directly display data on UIimageview
1 2 3 4 5 6 7 8 9 10 11 12 |
DispatchQueue.global(qos: .background).async { let operation2 = BlockOperation(block: { let data = try? Data(contentsOf: url) if data != nil{ let img = UIImage(data: data!) OperationQueue.main.addOperation({ productImage.image = img }) } }) self.queue.addOperation(operation2) } |