UIBarButton button image stretched width - uibarbuttonitem

Problem
After upgrading to XCode 9 and migrating my code to Swift 4, I've come across a few problems that I wasn't expecting. One of them is that the navigation bar in my app contains a button in the top left bar button item slot with an image, and now the image (and button) is stretched halfway across the screen for all view controllers (some have autolayout and some don't). Before XCode 9, it was working perfectly fine, and this problem only popped up after I updated XCode.
What I've tried
From this old SO post someone posted a recent answer that seems to suggest my problem stems from the different sizes for images in Assets.xcassets, but I don't understand why that would be a problem. I tried duplicating the image for the button and renaming it with "#2x" at the end (not sure what difference that makes...) and dragging it into the 2x slot in Assets.xcassets, and that somehow made the button slightly less stretched (about a third of the screen instead of about half). Overall, I'm just confused at why I have this problem, and would appreciate a solution that can fix my problem and explain why it worked before, but now doesn't.
Thanks in advance.

You have to set image view for bar button like this :
imageView is your bar button ImageView.
let widthConstraint = imageView.widthAnchor.constraint(equalToConstant: 32)
let heightConstraint = imageView.heightAnchor.constraint(equalToConstant: 32)
heightConstraint.isActive = true
widthConstraint.isActive = true

Hi RPatel99,
I faced the same issue. But I found a solution, set the image of your button to this sizes:
- image#1x: 22x22px
- image#2x: 44x44px
- image#3x: 66x66px
Unfortunately, I can't post photos because of my reputation.
Note: I try many different ways like change the frame of my button image but it doesn't work. If someone have an other solution, tell me, I'm interested.

Related

UIPageViewController and transparent page backs

Can anyone help with a problem with UIPageViewController giving transparent page backs?
I have a project displaying mock-ups of old newspapers. I am setting double sided to true and have slightly blurred and mirrored images for the page backs.
One prototype version is okay and looks like this as a page turns:
However, an updated version with different background looks like this:
As you can see, the curled page back is now completely transparent.
I think the code is the same in each case although the UIView hierarchy is different.
Can anyone help me out by explaining what might be the cause?
Many thanks!
This problem appears to be due to the fact that I had a sublayertransform in place that was not the Identity matrix. Resetting before using UIPageViewController fixes it.
let noPerspective = CATransform3DIdentity
self.view.layer.sublayerTransform = self.noPerspective
This clearly interfered with UIPageViewController's animation.

UITableView cells seems to fly in

I have weird problem on iOS 8 with dynamically resizing table cells.
While I scroll down table, cells which come in and appear seems to fly in. It looks like cell adjust width to fit iPhone 6 (like stretching from wider size).
How to prevent that strange behaviour.
read and learn about reuseIndetifier, it will speed up cell rendering and a must to use. And post code next time :)
iPhone - What are reuseIdentifiers (UITableViewCell)?
Definitely I know how to use reuseIdentifier and I do it.
Problem is completely different, maybe someone else met that kind of issue.

Xcode 6.0/6.1 Interface Builder resizes views to fit whole content when clicked on the corner grip to resize

I think this is an obvious bug on Xcode 6.0.1 but I'm searching for at least a workaround. In interface builder, I have an image view that is smaller in dimensions than the image that it contains. Here is my newly created, fresh nib with just an image view, the heart image is a larger PNG file than the containing image view:
So far so good. However, when I click on the any of the grips at the corners/edges of the view to resize the image view, it immediately changes to this the very moment I click on the grip:
This happens whenever I try to resize by hand (I can resize using width/height values at inspector though) and I have hard time trying to fit my design into the nib. The problem happens both on nibs and the storyboards. Does anyone know a workaround?
UPDATE: I've updated to Xcode 6.1 but I'm still having the same problem.
The same result I've noticed when close and reopen the project. The view continues to grow up every time. I have created a simple project to search the cause of the wrong behavior of the autoresizing mask (flexible width AND align to right).
So, try to disable "flexible width/height" and "align to right". Keep the "align to left" only.
This answer is for autolayout-enabled views/nibs. For autoresizing mask solution, see Nicolai Nita's answer: Xcode 6.0/6.1 Interface Builder resizes views to fit whole content when clicked on the corner grip to resize
I've solved the problem by setting the content compression resistance priority (both vertical and horizontal) to 250 from 750. I don't know why it wasn't the case before Xcode 5 though.

UIImageView inside UIScrollView bleeding over next page

I have a UIScrollView and a UIPageControl with 5 pages. Each page is set at a different background color. Each page is 1024 x 768 and only landscape mode is supported and the content size is set to: scrollView.contentSize = CGSizeMake(1024 * 5, 768);
Each page shows the right background color with the right size.
I place a UIImageView on each page which I can move around. From page 2 onward (or index 1), if the image is moved to the left age and onward it bleeds over to the previous page, you can actually go to the previous page and see part of the image there.
The same however does not happen for the right edge. If the image is moved past the viewable area, you don't see the image on the next page.
My question is how is this possible and what can I do to prevent it?
Thank you in advance
After much playing with this, to help others that may run into the same situation, the answer to this problem is to set:
self.view.clipsToBounds = TRUE;
on the view where your UIImageView(s) are added as a subview. For me, each page was an instantiation of a UIViewController class with the view set to the bounds of the window.

Label not showing at runtime at the same place it is in storyboard

I created an PNG for the background and used with an Image View. The image has a sentence which is: 'Relação Risco/Ganho:'and is followed by the result that will be shown up through a Label. The Label was positioned at the same baseline as the text in the image.
When I ran the app it was working fine yesterday, but today all of a sudden the Label does not appear at the same position it is in storyboard.
Below are the the screenshots.
So anyone have an idea what is causing this??
Thanks!!!
Make sure that your autoresize options are set correctly.

Resources