UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more 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.