Autolayout with UIScrollView containing dynamic TableView height - ios

I have a little problem, I work with Xcode 6 and now as we could see Apple advised to use Autolayout in our apps... And now that's compulsory.
So, I have that problem: I want to layout the ScrollView and the TableView but, I don't know how to do because I'm not an expert of autolayout...
The TableViewCells are dynamics, and appears by a specific action (for example: when a button is tapped) and the ScrollView's resizing automatically and that's the same for TableView's height.
As I said, I want the TableView's height and the ScrollView's height to change automatically and to adapt autolayout with this... But I don't have any idea yet...
Is anyone able to help me ? Please, if you have an idea tell me to hope to solve the problem !
Thank you in advance, and have a nice day ! (sorry I really wanted to post images but I can't currently because of reputation....................)

I always put something with blue lines, so I can use AL's suggest constraints at the third button on the bottom right, or use option + shift +command + '=' key to reset suggested constraints.By the way, Watching Stanford ios7 lecture 9 on itunes U is a good way learning autolayout.

Related

Need guide/resource/help on creating this UI on Swift with UIKit

Hi there, just like what the title says, I am in need of guidance/help on how to achieve similar UI design style as what's embedded above. I understand using UIKit could be harder as opposed to SwiftUI, but I am told to use UIKit as part of my study. Any help is much appreciated.
Edit:
We could start from the top, IE: maybe it's a custom collectionView? or static tableview?
Is the "variation" tab a collectionview inside a tableview cell?
How to achieve the "buy" and 'sell" section?
I always use UIStackView for multiple views like this, it's easy to setup, to configure and to update.
orange views are vertical UIStackView, play with spacing, distribution and other properties of UIStackView to get it fit.
Also if you think height of views get bigger of user screen, simply drop root stackView to UIScrollView, find out more how to have scrollable UIStackView
Masoud provided a great answer regarding the layout of the screen.
as for the question "How to achieve the "buy" and 'sell" section?",
You might be interested in the UITextField's .layer.cornerRadius property.

swift 4 and Xcode autoLayout and UIImageview as Button

I am working on auto layout and making those UIIMages as Button.
I would like to make those button to be clicked and switch the images
as well as showing some words in the label.
In this case what should I do?
In addition, as it is shown, the auto layout ratio is different only from the iPhone SE. In. this case What should I consider?
Many thanks,
The first thing you need to learn is auto layout. Start with basic Always go with Apple's doc first
This one I likes he is good and you will also find how to use buttons as image view, using card game example, check other tutorials also very helpfull.
Stanford university autolayout by Michel Deiman
As far, your question just gives your label Horizontal in the container constraints(open storyboard in the right bottom third from last (allin) click on it popUp will open), and 20 bottom to the buttons and it will be in the centre. Every elements need x,y height and width so it knows exactly where to place, so you also need to give constraints to the buttons, Learn stackView to understand how to place your button without giving many constraints to each button and stack view will handle it for you, try hide and show to one of the button and magically stack view will adjust all adjustment. I suggest before staring Do read apple's doc first.
And Your question is too broad to answer, so read and try adding different constraints based on your need and ask a specific question(after trying by yourself) like why this label getting cut what constraints should i add so people know exactly what you want to achieve, people are always ready to help, just ask the right question.
happyCoding

AutoLayout with ScrollView in Swift

I have just joined iOS Develepors world.
i have a questions.
I don't understand auto layout with scrollview. Im tried every kind method but everytime seen different size and different location (button).
I just want to create scrollview (hortizonal) on 12 buttons for all IPhone models. What should i do? Could you write details.
Thank you so much.
It's pretty easy, you just have to be really methodic with all the constraints you add. I always start from the outside constraints and then start adding the inner ones.
Check out the tutorial I wrote for implementing a UIScrollView + Auto Layout in Swift. If you have any doubt, just ask me :)
https://www.dribba.com/blog/2015/07/21/scrollview-autolayout-ios8-swift/

ScrollView using storyboard

I'm new to swift programming and storyboard usage. I want to know if it is possible to place my views inside a ScrollView using Storyboard and AutoLayout but visually. I'm not an expert so programming the constraints is a little hard for me now.
If it's possible can someone point me to a good starting point using xCode 6+. I'm planning to use iOS8+ as a requirement.
Thanks all!
It's pretty easy!
I've written a tutorial that explain how to use UIScrollView with Auto Layout in iOS 8 and Swift.
Take a look, hopefully will help you :).
https://www.dribba.com/blog/2015/07/21/scrollview-autolayout-ios8-swift/
Yes, it is possible. I do it all the time in my current projects.
Just make sure you connect (auto layout constraints) your scrollable contents to all sides of the scrollview, so that it can calculate the content size correctly.
Autolayout + UIScrollView is not a simple topic. Apple has a technical note on it:
https://developer.apple.com/library/ios/technotes/tn2154/_index.html
I found these tutorials useful:
http://natashatherobot.com/ios-autolayout-scrollview/
http://mobileoop.com/auto-layout-advanced-techniques-for-ios-8-and-7-using-xcode-6-on-storyboard
http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/?utm_source=maniacdev-ao&utm_medium=social&utm_campaign=uiscrollview-autolayout-ios

UIScrollView zooming only to the size of UIImageView

I have UIScrollView in which UIImageView is held like on the screenshot:
My problem appears when I zoom and instead of being able to scroll only in the area of my image (subview of scroll view) I'm able to scroll around the original size so I get a lot of white space around my image which isn't what I want. You can see what happens on the screenshot below:
I wonder what should I update to keep my scrolling area only the size of the image?
After some research, some trials and errors I've finally achieved what I was planning to do.
First of all, I wanted to use only autolayout with IB which sure can be done but with some effort. After some digging I've found this technical note which by "Pure Auto Layout Approach" understands adding contraints in code but I was aiming at only IB which led me to this simple but beautiful solution called ios-imagescroll. After investigating this code with joy that I've finally found solution I came with some error but only on iOS 8 devices... iOS 7 worked like charm out of the box.
I assume that due to big changes in iOS 8 autolayout is more strict and you must be 100% sure what you want to accomplish. It turned out that this slight change MATTERS on iOS 8:
Of course, this bug, fix (call it whatever you like) was fixed by experimenting with everything but I guess that UIScrollView's content view (in that case UIImageView) must be the first item in constraint.
[yourScrollView setContentSize:CGSizeMake(yourScrollView.size.width, yourImage.frame.origin.y + yourImage.frame.size.height+35 )]; //let's say just 35 ...
yourImage may have x,y origins like (0,0) [I see a lot of space above it, so I assume you have set other values for x,y]

Resources