iOS 9 UIImageView scaling is erratic - ios

I have a UICollectionView in my app. Each cell is about a third the width of the screen (in portrait orientation) and is square. Inside each cell is a UIImageView whose mode is set to "Scale To Fill" (in IB) and has constraints on each edge that force it to fill the cell.
On iOS 7 and 8, images would consistently perfectly fill each cell.
On iOS 9, scaling varies each time the view appears, and sometimes changes when the cell is clicked:
images sometimes are small, and sit in the upper left hand corner
images sometimes scale to fill as they should.
images sometimes scale slightly larger than the cell, and change size when the cell is selected.
images sometimes disappear completely when a cell is selected.
If it somehow matters, the image gets set in the cellForItemAtIndexPath method of the collection view like this:
cell.artImageView.image = artImage;
Where "artImage" is a UIImage. (Obj-C).
UIImageViews are pretty simple and straightforward. Did Apple "improve" them with some new property I need to set? Really stuck here.
Update: Tried to reproduce this in a new project and couldn't. Some kind of weird leftover IB juju. But totally replacing the collection view controller, cell and image view in IB did not fix the problem.

It turns out there was an extra view that wasn't "installed" for the size class.
I had this:
And changed it to this:
And now everything looks right!

Related

Everything moving up ion view when UIImage doesn't exist

I have designed a UIView where there's an UIImage at the top and under it there's an UILabel. Both of them are populated by JSON and sometimes there won't be an image to load so I want that when this happen, the rest of the stuff in my UIViewController move up so that the space in the picture doesn't exist.
And, actually my image isn't appearing anyway, this is my code:
self.imagen.kf_setImageWithURL(NSURL(string: "http://elpenitente.playcofrade.com/img/upload/\(idfoto)")!)
If you have a scroll view on your screen: Unchecking adjust scroll view insets in the inspector may solve your issue.
If not you probably have size constraints that your not noticing. Check the different screen configurations.

iPhone 6 Plus show strange lines in UITableViewCell next to the accessoryView

I have a UITableView that is showing some strange thin grey lines next to the accessory view. This ONLY happens on the plus, no other iPhone shows this issue.
It seems to have something to do with the imageView that is assigned to the cell. Some images cause the line, others don't, seemingly based on their dimensions.
Has anyone else seen this or know how to get rid of it?
I experienced this when using a UITableView that was partially covered with an SWRevealViewController.
When the calculated value of the tableview width was a decimal number, artifact lines between the content of a UITableViewCell and the accessory view would appear.
The solution was to make sure that size calculations for the view were rounded to whole numbers.
It looks like that line is from the right edge of the cell's content view. I don't know how it works, but my solution was:
cell.backgroundColor = .clear

iOS UIImageView beneath UITableView doesn't display correctly

I'm building a UITableView via the StoryBoard in XCode 6.3.1 for iPhone 6 app.
On this TableView, I want all of my cells, then beneath that, a UIImageView. I tested it for a small placeholder image, and it worked great. All of my cells display properly, and the image shows up beneath them.
The problem comes when I use my actual image (it's the size of the full screen). I want it to go directly below the Tableview, and have the bottom be viewable when the user scrolls down.
I tried messing with the view's attributes, and everything kept giving me some sort of issue. The default view mode of "Scale to Fill" makes the image look extremely distorted. Changing it to Aspect Fill makes the Image look perfect, but it makes all of the cells disappear when I run it (though not in the Storyboard for some reason)
Is there any way I can get the cells to display correctly, then place the undistorted image beneath it?

Detail Text and Accessory Don't show [duplicate]

I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.

Custom UITableViewCell elements getting cut off in the Interface Builder

I'm just getting started with iOS development. I am trying to make a custom UITableViewCell for an iPad-only app.
I am using XCode 4.2 and the latest iOS 5 Beta.
When I'm trying to build my interface, I can't place an elements or make any elements wider than about half of the cell size that's displayed. In the screenshot attached, I want to place the "Name" label on the far right side and stretch the progress bar to the far right side as well. However, when I stretch the progress bar out any further, it just gets cut off.
I'm sure I'm missing something...any ideas?
If it is allowing you to stretch the progress bar the entire length and then cuts it off after you release it, then there is probably another object (i.e. custom button, image view, etc) on the right portion of your cell that is higher on the view stack.
Check in the Objects section of Interface Builder to see if that is the case. Then you can adjust accordingly.
I'll like to make a little guess here...does it have to do with the orientation of landscape/portrait? It looks like the cell is landscape but the view is only for portrait...
check every controller with background color property. set the different color for every one. Might be it's overlapped one view over second view.

Resources