iOS Swift trouble making detail page with embedded list and collection view - ios

I am new in iOS development and Swift, I'm struggling creating a relatively simple detail page.
For now I have this layout made with interface builder:
The parts highlighted in red must have variable heights, every element is inside one big stack view which is inside a big scroll view.
The list of phone numbers is a label with Lines set at 0 so if I understood correctly that element will size itself correctly with the content.
I don't know how to implement the other two lists and how to make the whole layout to wrap onto the content.
To make you understand better I'm struggling because I'm used to make layouts in android and so making extensive use of the wrap_content option.
Thanks in advance

I think, you could use UITableView for image+text list and UICollectionView for images. If you are using constraints you have to add height constraints to your tableView and collectionView, but you could update those constraints from code with real heights.

Related

UIImageView streches over entire row height of UITableViewCell

Intro: Hi, I'm working on a "News" app, that uses a news API online. I want to display the content of the latest news in a TableView (Currently I want to display the title of the news item, the name of the organization that posted it (e.g: the BBC), and an image that I load from a given link). I dragged a table view in the Main storyboard, created a custom cell for a singular news item, and get all of the required information from the internet.
The Problem:
When all the data gets loaded into the TableView, the image streches across the whole rows height.
I'm trying to find a work-around for hours now. At the moment, In the prototype cell, I have a Stack View, that contains 2 labels and an ImageView, with a Vertical Axis, and a Distribution of Fill Equally.
There are no constraints on the Views inside the Stack View (the 2 labels and ImageView), and I'm not editing any constraints within the code, to keep it as simple as possible.
I also tried the constraints approach prior of using the stack view, but it gave the same result.
Image Of The Stack View
The Result in the Simulator (Rows without an image, don't have an image url provided by the api, so I just skip them).
I tried being as expressive as I can about the problem, if you are still missing some information please let me know
The problem you are encountering is due to constraint issue. The problem should be solved by unstacking the view and put constraints instead.
You can still achieve scalable application using them.
If you are confused with how to do it, refer https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html
These should help.
I think you are in right Direction.
if you want static(fixed) Layout Follow below step.
change StackView Distribution from Fill equally to Fill
Apply StackView(leading,trailing,top,bottm) =
cell(leading,trailing,top,bottm)
set tableView rowHeight to 300 or whatever you want
if you want dynamic layout follow below step
https://www.raywenderlich.com/1067-self-sizing-table-view-cells

Is subclassing UIView the right way to go about an unknown number of these custom objects?

I have a screen in my app that pulls an unknown sized array from my user object, and must display an object for each item in the array that consists of a UIImageView for my background image, a UISwitch to activate/deactivate that particular item, a label with the name of the item, and a label that corresponds to the name of the item.
These are displayed in a UIScrollView, since there are nearly always going to be more items than will fit on the screen, especially on the iPhone 4.
I had initially quickly thrown together a static screen that consisted of 20 of these objects, but have found that I will often be exceeding that number of items in the array, and need to convert to a dynamic solution.
I have not used subclassing at all yet, and want to be sure that this is the proper solution before I dive into the implementation. Adding one subclass to my scrollView sounds a lot cleaner than adding each of those components individually and figuring out the spacing for various screens.
If this is the proper solution, are there any resources you could point me to to learn about how to properly do this subclassing? I.e., how to add a constructor for the objects where I can add the contents of the labels and state of the switch, and programmatically add constraints. I've only used constraints from the storyboard.
If you do not think that subclassing UIView would be the proper way to do this, what other solution would you suggest? I'm admittedly a novice when it comes to iOS development, so I apologize that this post seeks advice on where to start rather than help fixing a specific part of an implementation.
You should use UITableView or UICollectionView for that, and subclass UITableViewCell or UICollectionViewCell to create your custom view hierarchy.
UITableView and UICollectionView will handle reusing of cells which will help in memory management.
Update:
as you want to use UITableView so to add spacing between cells set number of sections to number of elements and then add header for section and set its height you can do that by implementing UITableViewDelegates visit below links for detail about UITableView and UITableViewDelegates
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/

Clickable tags / text

I'm working on an app that includes the names of users with their icons under an image. I'm currently using collection view in order to distribute the names. I'm using this approach since each cell when clicked will be holding the user object. However, I'm having some layout issues when it's used (please check attached image). The spacing is unusual. The desired output is the cells having a certain spacing limit between them and if any cell cannot fit, will be placed on the other line. I tried using the delegate methods for spacing by setting it to 5 however it's not working (the cell's size will be dynamic). Should I subclass and create my own Collection view Layout ? if there is any other approach without using collection views please let me know. Thank you.

RichText label or 'flow' layout for text in iOS (Xamarin/MonoTouch)

I am trying to repduce a similar sort of layout as in the screenshot below from the Digg app..
Notice that each list entry has a title in bold followed by the source, posted time and finally if there is enough space the start of the description line.
The question is what is the best way to achieve this in iOS? With some posts having longer titles than others I cannot simply say that the title label is 40px high and then place the Source label at 45 as the title will sometimes be longer and sometimes shorter.
Do I have to calculate the height of the label based on its contents before arranging the layout or is there some better way of doing this in iOS so that the views 'below' are automatically moved down?
Another alternative would be some sort of rich text label that I could add all the text to and have it automatically wrap round moving the later text down but I cannot find any sort of control in standard iOS / Xamarin (MonoTouch).
Any pointers would be greatly appreciated?
If you are using a storyboard the simplest way to achieve this result is to define different prototype cells. For example, you could define four different prototype cells, each one with a different layout like those shown in the example picture you provided. You can dequeue the appropriate cell based on the content you want to display so there is no need to adjust the layout in the code.
If you are doing everything in code, it's a lot more complicated since you have to build your own "layout engine" to adjust size and position of the views in your cell. You can have a look at XibFree or use MonoTouch.Dialog as suggested in the comments.

If I have different UI controls to display sequentially, should I still use a table view controller?

I want to implement something similar to this- (focus on the left portion)
I imagine possible implementations to be
Making a table view with (in this case) 7 'normal' cells, one normal size cell with a custom right accessory item, one 3XL cell containing a button, and finally a normal size cell with an imageview and custom accessory item.
or
Making a scroll view with styled view containing UILabels masquerading as 'cells', a button within a larger UIView, and another faux view-with-label-cell.
Considering the challenges posed by different screen sizes, and the want for easy configuration and modification- which way should mixed sequential data be displayed? Hacky table view, redundant scroll view, or reinvented custom UIView?
Edits
I am currently using a sliding view controller. The sliding functionality is of no worry to me, the contents of the scroll/table view within is.
There are various open source libraries available on net/github. you can use this https://github.com/edgecase/ECSlidingViewController.
Although you can make your own if you want but doing this using scrollview I don't think it will be a good way to do that.
Edit
You basically have to create 8 normal cells and change the color of the cell label which is selected. And create a footer view of YUTableview for last view.
You can use Slide-Out Navigation Panel. Use this slide-out-navigation for better understanding.
I've found more information on this, and I definitely overcomplicated a simple matter.
The answer is yes (use the table view), and there are multiple reasons- the first being the principle of always using the highest level of abstraction where practical.
StaticUITableViewCellsare completely capable of rendering other UI elements (buttons, sliders, etc) inside themselves from stock, and this is encouraged in Apple's UITableView spec. Dynamic cells, stock, are not as flexible but they can be subclassed from UITableViewCell for more custom functionality.
To speak for the example, the first X (in this case, 7) cells are likely dynamic, and the last 3 cells are static. The 'second to last' cell seems to have an infinite(?) height, and the last cell appears to be a sticky tableview footer.

Resources