ScrollView with multiple Views iOS Autolayout - ios

I am a newbie iOS developer currently working for a small company. I started developing iOS only some months ago and i only know how to work with Swift and AutoLayout. I have a little bit of a situation since my boss asked me to do a complicated scrollable view that contains other type of views within it.
I made a sketch using wireframe that is available here: https://wireframe.cc/MU0PC6, and i will also leave a print screen. So my question is: Is this achievable using AutoLayout and Swift? If it is can you please help me do it? If not, can you please point to a good tutorial that can help me do it using nibs?
Thank you, and sorry for my english and newbie skills.
Here is the screenshot

In order to create complex scrollable layouts with different elements and sections you should use a UICollectionView.
You can read into it here:
UICollectionView Tutorial
All the different parts of the layout would be individual UICollectionviewCells and you can control the size of them through UICollectionViewDelegateFlowLayout.
You can also build it using just UIScrollView and AutoLayout of course but the UICollectionView approach saves you a lot of headaches and when developing for iOS the UICollectionView is one of the most vital UI components anyway.

Related

iOS customise user interface

Hi all I would like to make a horizontal scroll bar like below in iOS APP.
I read through lots of iOS programming book, none of them teaches me how to do custom UI. Can someone tell me, what knowledge I should learn in order to make this?
Thank you.
You should be using UICollectionView to make your life easier. There are many tutorials on that in which you probably just want to lay out your cells in one row and many columns to achieve the horizontal scrolling effect. Otherwise you may want to employ external libraries like this if you prefer a plug and play solution.

Multiple xib for defining a page?

I'm implementing a lock-screen page in iOS.
But the design for iPhone 6 requires text on top is pretty large, which causes the bottom in the page is hidden in devices equipped with small resolution screen like iPhone 4.
Do I have to define multiple xib for each device in this situation?
Or make some views smaller programmatically?
Or make some margins smaller programmatically?
Are there any references for this? I'm new to auto-layout.
I would suggest you to use autolayouts. From my understanding your app can be implemented with stack views.
So start with this document,
http://www.appcoda.com/introduction-auto-layout/
and
http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-auto-layout-basics--cms-25520
Then checkout the apple documentation for further understanding
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/
If the constraints are too confusing, try stack views
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AutoLayoutWithoutConstraints.html#//apple_ref/doc/uid/TP40010853-CH8-SW1
Creating multiple xibs is not a solution. Make use of autolayouts :)

Is it a bad thing to create views programmatically? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
So I'm new to iOS development and I found it easier to write the views all programmatically. So my views have UIViews, ScrollViews, UIButton, UILabel all created and positioned programmatically. (So I never used AutoLayouts).
I've now pretty much finished my app and want to make the iPad views, and realized maybe it was a bad idea to do it like this.
Is this bad practice or should I really be using auto layouts as much as I can?
If it's ok to do it how I'm doing it right now, what is the correct way to add different views for iOS and iPad? I've seen this answer below on how to find the device, is a simple if else statement sufficient? - iOS: How to determine the current iPhone/device model in Swift?
I am using programatic views in a live app and its awesome. A bunch of people I know us this as well.
Here is a little algorithm I use to choose between the two methods:
Are you building a fast app for a client or a hobby? Use storyboard with autolayout.
Are you building an open source project that will be used by many people? Use programatic UI
Are you building an app for the long run? (1+ year) Use programatic UI
Its also harder to make an app thats supposed to be rotated without autolayout. Because doing that with code takes much more work than autolayout. Most good apps dont use this feature anyways so I don't see much problem.
A good tip is never to use constants while writing programatic UI.
If you are going to make a button thats 100px in width, do not type in 100px anywhere in the code. Instead figure out the screen sizes and place the main views according to screen sizes. Then place the subviews or secondary views according to the position of the main views. If you do this correctly you will have more powerful multidevice layout support than autolayout.
Here is a little library I wrote, please inspect and play with the code on how I place the view: https://github.com/goktugyil/CozyLoadingActivity/blob/master/CozyLoadingActivity.swift
Also here is a good article I like about this:
http://www.toptal.com/ios/ios-user-interfaces-storyboards-vs-nibs-vs-custom-code
This is only fine, If you have enough time, patience, good skill on calculations and relationship configurations between different UI elements.
However, using Auto Layout is pretty useful and low time consuming than manual calculations.
We can easily create a dynamic and versatile interface that responds appropriately to changes in screen size, device orientation, and localization with minimal effort.
Read Adopting Auto Layout,to implement the Auto Layout in your existing application
TL;DR
It depends
Longer version
Clearly one size does not fit all. AutoLayout is pretty powerful both in Interface Builder and code (be it visual language format, or simple constraint setting), but sometimes it just seems like you're "rubbing your right ear with your left hand" - that's when adding views programmatically comes in. But beware of not having it different in each view controller - you don't want to introduce too much complexity in your project, right?
I personally like using AutoLayout as much as I can and whenever I can't use it anymore, or the StoryBoard View would get too messed up with millions of constraints, I try to separate views into containers - have the container be resized by AutoLayout and have the subviews handled by code.
Example would be a custom Media Player - maybe I want to have two stripes below and above the video - I could have the video and two UIView extended stripes handled by the AutoLayout. But the subviews (controls) in the stripes themselves would be added by code. It gives me the control over my code but still it doesn't introduce too much complexity.
First of all - if you want to develop for iOS you have to learn Autolayout. There are already a lot of different devices with different resolutions and maybe will be even more in future.
Secondary - if you want to work effectively with IB you have to read guide / watch tutorial videos and have some practice. It could be difficult to start but then you will realize that IB is powerful, fast and often the best way to develop GUI. Often, but not always!
Code advantages:
Easy to copy-paste and reuse GUI. It could be critical if you have
several similar views or want to reuse some old code.
Easy to resolve merge conflicts and check commits.
Easier to make styles - like the same font for all labels depending on the country.
More powerful (there are things that could not be done with IB) so you have to use it sometimes.
IB advantages:
You can see your GUI during development for different resolutions/localizations so you do not have to compile and run a project on different devices/simulators to check is GUI ok or not. Also IB will show you warnings if you forget some Autolayout constraints or there are conflicts. Saves a lot of time if you have a complex GUI with non-trivial Autolayout constraints.
It is much easier to understand someones else code if it is developed in IB. Especially important for complex GUI - not so easy to find a required label or button in a few hundreds lines of code.
Small bonus - if you want to use a custom control developed via code you can make it IBInspectable and use it without problems in IB
Just to summarize - if you do not need IB benefits (for example GUI is quite simple and does not use Autolayout) developing GUI via code could be easier and faster. But in case you have to support different resolutions and/or you have hundreds lines of GUI code in each view controller I strongly recommend to try IB.

iOS 7 Transition - XCode 5 - Interface Builder - Three20

I've currently an App (with a lot of View Controllers, ...) what uses the "discontinued" Facebook three20 Library and any storyboard, xib file.
Now I need to update this App, the Deployment Target will be iOS 7 and I have to build it with XCode 5.
So my questions:
Is using the Storyboard a good Idea? Would you suggest me to recreate all View Controllers in the Interface Builder?
--
Another question: when adding a Label Programmatically using iOS 7 feature
self.edgesForExtendedLayout = UIRectEdgeAll;
how do I set the Frame for this Element? Need I determine if I am in Landscape, Portrait and Add the 20+44 for example manually to the y-Axis to start under the NavBar or are there better ways to solve this problem?
Storyboards are good, and you should absolutely use them in any future app you make. Whether or not you should rebuild a current app to use storyboards is a question of how big the app currently is, how much bigger it might get, how much longer you'll support it, etc.
If the app is already pretty massive and it won't necessarily grow much at all from here, it's probably not worth the effort to convert over to storyboards.
If the app is only a handful of view controllers, but you have big future plans for it, I'd take the time to convert it over to storyboards so that all the future development will go faster/easier.
I don't deny storyboards but I respect the custom view approach. It means I am creating my each & every component programmatically via code, be it a UILabel or a UITableView. Aligning code with ios7 specific requirements can also be handelled & controlled at granular level using custom View approach.
To your questions about setting frames for the element or detecting device orientation can very well be detected & adopted by writing code.
You can search more help as the information is available all around on programming aspects of iOS.

UI Controller like in Apple's Book Application?

First of all I'm new to IOS Development!
I have a plan to build an app which should look similar to the Book app provided by Apple.
My question is, that what kind of UI Controller does that app use for displaying the books on a shelf?
Is that a custom one? Or just a couple of UIImageView's placed on a UIView?
Thanks in advance!
It is a custom view created by Apple but it wouldn't be too difficult to replicate with a background image and a UIScrollView where the books are placed based on calculation on spacing
Edit: Maybe using a Library such as AQGridView would help you with the spacing of the books on the Shelf

Resources