GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

SOLVED: PROBLEM: Milestone: Projects 1-3

Forums > 100 Days of Swift

I've gotten pretty far today on this and I'm about to call it a day but it's KILLING ME that I can't figure out how to get a small border around my image in my DetailViewController after passing the asset through from the ViewController.

if let pushedFlagImage = selectedFlag {
            imageView.image = UIImage(named: pushedFlagImage)
            imageView.layer.borderWidth = 0.5
            imageView.layer.borderColor = UIColor.black.cgColor
        }
    }

it feels like I've tried every permutation of imageView.layer. If the imageView didn't take up the whole screen the border covers and entire outside of the bound of the UIImageView but not the actual photo.

Any tips?

3      

@Haibo  

Set the aspect ratio of imageView to 2:1 in your storyboard should solve your problem. To do it, control drag your imageView to its self or click the "add to new constraints" icon in storyboard, it is a little square icon at the bottom.

The problem here is your imageView's aspect ratio is not aligned with your flag image's aspect ratio. As your countries flas image is all 2:1, 600 300 or 400 200.

Otherwize you could set a fix imageView height in storyboard like 200 or 300 per flag images you are using.

4      

I likely did everything you said wrong BUT i did fix it by getting frustrated by putting a placeholder flag there and then clicking "Editor > Size to fit Contents", then "Editor > Resolve Autolayout Issues > Reset to Suggested Constraints"

It's working perfectly now! Thank you very much!

3      

Hacking with Swift is sponsored by try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.