I have a view controller, where I have a UIImage and UIlabels. This UIimage - image loads from the server and and the UIlabel text gets the value from the fields defined in the database. Now, in some records we dont have Images on the server and are blank, but there will be always the UILabel values. So if we dont have image value, how can we remove the UIImage and bring the labels up (as seen in the screenshots).
In the first screenshot we have the image so thats fine but the second screenshot we only have text and want to bring the text up. Is there a easy way?
Also, if we have various size image in regards to height and width, so how can we get the actual size of the image loaded on the app from the server
First Screenshot
Second Screenshot
code:
private func checkImage(_ imageString:String)
{
self.imageUI.layoutIfNeeded()
if imageString.characters.count >= 2
{
if imageString != "<null>"
{
let url = NSURL(string:"http://www.xyz.com.au/images/"+imageString)
let data = NSData(contentsOf:url! as URL)
if data != nil
{
imageUI.image = UIImage(data:data! as Data) //= UIImage(data:data!)
//imageUI.sizeToFit()
let data = NSData(contentsOf: url as! URL)
let Image = UIImage(data: data as! Data)!
DispatchQueue.main.async {
if data != nil
{
// We've received valid image.
// Find the height & Width of received image and update the image-view's height constraint.
imageUI.image = data!.size.height
}
else
{
// Sorry,The received image is invalid,Need to hide Image View,So make the Image-view height constraint's constant to 0 which eventually hides it self and pulls that below label up!
imageUI.constraints = 0
}
}
}
}
else
{
//logoImageView.image = UIImage(named: "error-404")
}
}
else
{
//logoImageView.image = UIImage(named: "error-404")
}
}