NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

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?

   

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.

1      

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!

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED Building and maintaining in-app subscription infrastructure is hard. Luckily there's a better way. With RevenueCat, you can implement subscriptions for your app in hours, not months, so you can get back to building your app.

Try it for free

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

Reply to this topic…

You need to create an account or log in to reply.

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.