I'm actually working on an IOS application, and i would like to see a background UIImageView in ScrollView.
My problem is that, i'm using Images.xcassets with this two pictures.
And there is my controller with those constraints.
On iphone6 and Iphone6+ i got this display which is correct
on Iphone5 i got that display with an horizontal scrollView
Can i adapt the background image to the device screen, without the horizontally scroll on iphone5 ?
I'm actually using Xcode 7.0.1 with swift.
UPDATED:
Screen with the same width between my imageview, scrollview and rootview.
The other screen with the programming way using swift.
As it stands, you've added the image as actual content of the scrollview.
Which is fine, if it's supposed to scroll with the scrollview. If you didn't want it to scroll at all you could put it behind the ScrollView.
You can disable horizontal scrolling, better yet, add constraints to the image view, such that it has its width = to the superview of the scrollview, i.e. the view controller's root view.
Once this is done, you may also wish to add "centre" as the content mode for the image view, or whatever you wish, as there will be extra content and scaling will look worse. If your view isn't wide enough for all form factors you may be force to use aspect fill.
Related
I am attempting to customize the default LaunchScreen.storyboard of my Flutter app. I simply have a red background on the default View, and I added an Image View as a child of it. This Image View is centered on the screen and renders an image that I have added to "Assets.xcassets" with all 3 sizes. Below is a preview of what my Xcode displays:
However, this storyboard renders differently on devices than it appears in Xcode. For example, it appears slightly off-centered on iPhone 12, and it is scaled up too high for iPhone 6s and is way off-centered. See below for screenshots:
As you can see, the storyboard renders differently on the two devices. How can I make the storyboard appear the same on both devices as it does in Xcode? Any help is appreciated. If I used any incorrect terminology or need to provide additional details, please let me know as I have minimal experience using Xcode.
From the storyboard screenshot attached, it looks like there are no constraints added to the UIImageView.
You should add top, leading, bottom & trailing constraints to superview with 0 spacing to achieve what you want.
UPDATE
Above is applicable to the case when you have a small size image like 100x100 or similar that can easily fit on all screen sizes. In the comments, we see that image is way too big and we want to keep it in center while occupying 50% of screen width.
Remove the leading and trailing constraints, select the imageView and it's superview - add equal widths constraint with a multiplier of 0.5, this will make sure that imageView will always occupy 50% of the superview's width.
Also add horizontally center constraint on the imageView. Make sure imageView Content Mode is set to Aspect Fit.
I created simple view to FlashCards, but when I try put autolayout on sign i have a problem. In xcode small white view size works fine, but when i run apps in simulator size is crashed. I have assets 2x and 3x. I tried make bigger view in xcode but when i do this view works fine on ip8, but ip8+ is too large
here sign is bigger than my view, and view dont masks sign.
but iphon 8+ works fine...
its my small white view contrains
well background is imageview with this img
, next i added white uiview on sign (which size is crashed), in next step i want add this sign: in white view to flips and changes words, all works fine when i created layout on one device, but when i try added autolayout size white view and content in this view is crashed
The simplest solution for this is to increase your current height and width values and then test it through all device screen sizes. Fingers crossed that you going to get wished result.
A second solution, which requires graphic editor software skils, is that you separate the sign from the current image, without background, let's say in Photoshop. And then use the sign image as the second image, which is located in separate ImageView. Position this sign Image View over current background Image View( with palms ) to fit your wished layout. Set leading, trailing and bottom constraints for sign Image View, and at the end set proportional height constant which is proportional to the screen height of your device.
If you screen height is 667, and your sign Image View height is 150, result is that your new sign Image View should be 22.48875562% height size of your device screen height size. See Proportional height of view and superview autolayout
for more details about proportional layout with swift.
And now you should add your UIView over sign Image View. When you've added UIView set top, leading and trailing constraints to be same as the constraints of sign Image View. And at the end, add another proportional height constraint which is proportional to the height of sign Image View.
The first solution is easy, and the second one is tricky, but I hope it helps. It's always tricky to sync UI elements with graphic parts of images.
I solved this. Reason break this view is tabbar, I created layout on view where i don't see tabbar. When I run apps and tabbar is shown view is smaller and constraints are break content.
I need to make something like this
the problem is 6 buttons in the middle, how to make it manually by using scroll view? I need to use scroll view since it will be a problem if in landscape mode
here is what I make
https://drive.google.com/file/d/10TBjW3qAaDEGJ_I_EQBPr5anzGcG1-er/view?usp=sharing
the problem is, in iPhone 5s, it seems it can be scrolled horizontally even though I have set width of content view to be the same as scroll view, and in larger phone, it seems not located centrally and not fill the screen
I don't know what went wrong with the auto layout
I unzip your project, and open the storyboard to check those constraint. You can change device to iPhone SE as the red rectangle marked. I notice that the Width of Content View is fixed with 375. It should be as the same as the width of Scroll View.
After updating the width of Content View constraint, I remove the Width:375 constraint, and apply new one that to equal to the width of Scroll View. It looks like the following image.
Hope those help you.
I am facing a weird issue. I have implemented custom UIButtons as a Tile View in a UIScrollView which is added to superview. It is like there are six buttons, set of two placed sideways, and next set of 2 below them and so on. Now for implementing it to fit all iPhones Screen Sizes, I have added proper constraints to UIScrollView and constraints to UIButton relative to each other and UIScrollView. I have added #2x background images to each of the button with resolution as 320 *320. I have not provided any heights and widths constraints to them, so that they stretch freely according to different screen sizes.
xib has been initially designed as a 4" screen size. UIScrollView frame is stretching, however button remain positioned as in an iPhone 5S xib, hence it is looking improper on screens like iphone 6 etc.
What is the exact problem here?
See the work done here and confirm if this is correct. I have added constraints required to make the buttons looks proper in all devices.
here is the link
https://github.com/mahesh-agrawal/Test-Buttons-Inside-ScrollView
I know there are a couple of questions around but I could not figure out how to do this (none of the answers there helped me), so here is my version of the question.
I have an UICollectionView which is set to scroll horizontally. Each cell has an UIScrollView inside and inside the UIScrollView I have an UIImageView.
Now, the images displayed by the UIImageView are loaded from the internet and I can't figure out a way to make the zooming work correctly using storyboards and autolayout.
If I set constraints that tie my UIScrollView to it's container everything is ok. The moment I tie the UIImageView to the UIScrollView XCode starts to complain that the UIScrollView's size is ambiguous.
If I don't make any constraints in InterfaceBuilder the images are not the displayed in the correct size (doh!).
So, I'm stuck. I don't know what kind of constraints to make and which view needs to be tied to what. I know that my perfect world result is a view controller that behaves like the native iOS Photos app. That is, the image is displayed as large as the screen (with a black band at top and bottom or left & right depending on image's orientation) and that you can zoom it in and pan it around.
Help please!
Note
I did read these posts before posting my own question
UIScrollView zooming with Auto Layout
UIScrollView Zoom Does Not Work With Autolayout
“Pinch to Zoom” using AutoLayout
I don't know if it'll help you with your zooming problem but Apple provided a technical note about using scroll views with auto layout: Technical Note TN2154, UIScrollView And Autolayout
The important part with scroll views is, that the constraints of the subviews inside the scroll view are not bound to the scroll view itself, but to the scroll view's parent (in your case the collection view cell)
It works
You can easily do it. Well not really easily, i have been struggling for quite a while!
I managed to implement auto layout within the scrollable area. Just it is vertical only
Set intrinsic size to a "placeholder" (to scrollable view)
Don't set contentSize at all
Attach right constraints to the wrapper (so it will be relative to the parent view)
self.view.addConstraint(NSLayoutConstraint(
item:self.view, attribute:.Trailing,
relatedBy:.Equal, toItem:contentView,
attribute:.Trailing, multiplier:1, constant:0))
scrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
So, in your case, your contentView right side should be attached the right side of the image
Try it out, certainly you will have your zooming to work
Here is an example, it may help you
https://github.com/nchanged/swift-content-manager/tree/master