launch screen xib not displaying imageview correctly
Asked Answered
E

2

8

I'm using a launch screen xib and I can't get the image within the UIImageView to appear. Currently, I have a UILabel with the imageView placed right below the label and also centered horizontally. I set all the constraints for the imageView but for some reason the label appears but the image doesn't. This is my first time using the whole wAny hAny size classes. Is there something I'm missing?

enter image description here

enter image description here

Ethnic answered 16/12, 2014 at 4:53 Comment(14)
Do you have all images for each resolution ? Are you using Images.xcassets ?Sada
No I'm using a xib, instead of launch imagesEthnic
Set center vertically and also set the fixed width and height of uiimage.Cutch
No, i am asking about Hand-White-Out.png, do you this image in all resolution ?Sada
@Balaji I added the center vertically constraint and aspect ratio. It got better but still off. 6+ image is still tiny.Ethnic
@Ethnic this is what you want ? dropbox.com/s/80zm4px6mh8c1s7/demoCanDelete%203.zip?dl=0Bulk
@Brosef: Can u show the image that you wantCutch
@Sada yes i do. I'm using the highest resolution version for the 6+ and setting the UIImageView setting to "aspect fit".Ethnic
@Ethnic can you write constraint in words that you want ? like image must have in center , label must be above the image view etcBulk
@Bulk not sure what you mean. I don't know where I would write the constraints since its a launch file xib.Ethnic
@Ethnic i mean write it in question, :)Bulk
@Bulk The image is suppose to be the same image that appears on the first view controller after the launch screen with the same (x,y) position and size. The image on the first view controller has a vertical space constraint to the top layout guide with a constant of 164. It also has a horizontal centered constraint and aspect ratio. It also has a equal widths constraint with a multiplier of 88:320 to the superview.Ethnic
@Ethnic You first set proper constrain wAny | hAny? (because your print-screen have only wCompact and hRegular.Bulk
@Bulk I set the xib to be wCompact and hRegular because it is only in iphone portrait style. Not sure if this answers your question.Ethnic
G
4

This is happening because of the horizontal space constraints of the imageView, both the leading and trailing space to the superview. Here the launch screen is laid out in the wAny|hAny size class. It could not satisfy the Horizontal space -(196) on a smaller device. So what you can do

  1. Remove the horizontal space constrains(both leading&trailing) of imageView
  2. Add widthconstraint to the imageView or Aspect Ratio could be more appropriate
  3. Other constraints looks fine, top & bottom spacing and centre horizontally in container keep as it is
Gladysglagolitic answered 16/12, 2014 at 5:42 Comment(6)
Someone in the comments advised me to set the width and height, but I just set the aspect ratio thinking it would achieve the same result. When I went back and set the width and height constraints it all worked. However, the image isn't getting bigger when going from the 5 to 6 to 6+. It just stays the same size. How can I get it to grow with the size of the screen?Ethnic
if you add the with&height constraints imageView remains same, it wont resize accordingly. Use the Aspect Ratio instead. So that when the height increases(it would happen automatically by the top & bottom space constraints) the with also get increased.Gladysglagolitic
I removed the width and height constraints and replaced with the aspect ratio. However, with width and height constraints gone, I'll have to implement leading and trailing again to satisfy the requirements.Ethnic
I hope now u have.. top&bottom space, aspect ratio and horizontal centre in container constraints right?Gladysglagolitic
I do, but the image is very large. Even on the iphone 5 its very big.Ethnic
Use image with proper resolution or you could fix the width. Dont know a proper solutionGladysglagolitic
C
6

Based on my recent experience, it appears that as of iOS 8.3, any images in the launch screen XIB have to be in the image assets. I do not know if this is the OP's problem or not, but definitely worth mentioning for other folks coming here with the same issue.

Constitutional answered 10/5, 2015 at 3:31 Comment(6)
I'd like to think this is problem I'm having. But I put the image into Images.xcassets, and it is still not showing up - just as the OP describes it.Temuco
I had this problem in iOS 9 and this solved my problem.Abominate
@Sandy, is your image in the image assets? Can you view the image in your storyboard?Constitutional
from assets it's showing but from launchimage it's not.Optical
from assets it does, but from launchimage no.Optical
I Use iOS 9.. images are there in assets... Still not seeing :(Sober
G
4

This is happening because of the horizontal space constraints of the imageView, both the leading and trailing space to the superview. Here the launch screen is laid out in the wAny|hAny size class. It could not satisfy the Horizontal space -(196) on a smaller device. So what you can do

  1. Remove the horizontal space constrains(both leading&trailing) of imageView
  2. Add widthconstraint to the imageView or Aspect Ratio could be more appropriate
  3. Other constraints looks fine, top & bottom spacing and centre horizontally in container keep as it is
Gladysglagolitic answered 16/12, 2014 at 5:42 Comment(6)
Someone in the comments advised me to set the width and height, but I just set the aspect ratio thinking it would achieve the same result. When I went back and set the width and height constraints it all worked. However, the image isn't getting bigger when going from the 5 to 6 to 6+. It just stays the same size. How can I get it to grow with the size of the screen?Ethnic
if you add the with&height constraints imageView remains same, it wont resize accordingly. Use the Aspect Ratio instead. So that when the height increases(it would happen automatically by the top & bottom space constraints) the with also get increased.Gladysglagolitic
I removed the width and height constraints and replaced with the aspect ratio. However, with width and height constraints gone, I'll have to implement leading and trailing again to satisfy the requirements.Ethnic
I hope now u have.. top&bottom space, aspect ratio and horizontal centre in container constraints right?Gladysglagolitic
I do, but the image is very large. Even on the iphone 5 its very big.Ethnic
Use image with proper resolution or you could fix the width. Dont know a proper solutionGladysglagolitic

© 2022 - 2024 — McMap. All rights reserved.