Display a list of items in horizontal Swift


I'm making an app that shows the weather information.

I have the view divided into 3 sections:

1- A Uiview with information about today's weather

2- A UITableView with the following days of the time

3- A horizontal table with time by hours for today (Here the problem)

I used the ASHorizontalScrollView library but all the items are horizontal.
Let me explain: What I want is for a small icon to appear with the time and temperature, for each hour. The problem is that I do not have one under another, but everything horizontally.

All the items should go out horizontally, but within each item, the 3 items, one below the other.

Do you know any bookstore or code to work more or less as I explained?

Here is an example of the code:

    let horizontalScrollView:ASHorizontalScrollView = ASHorizontalScrollView(frame:CGRectMake(0, 0, vistaScroll.frame.size.width-12, 50.0))
    horizontalScrollView.leftMarginPx = 0
    horizontalScrollView.miniMarginPxBetweenItems = 0
    horizontalScrollView.miniAppearPxOfLastItem = 0
    horizontalScrollView.uniformItemSize = CGSizeMake(50, 50)
        //this must be called after changing any size or margin property of this class to get acurrate margin
        var valorArray = "01"
        for index in 1...24 {
            if index < 10 {
                valorArray = "0" + String(index)
            else {
                valorArray = String(index)
            let estado = currentArticleToDisplay.estadoCielo[valorArray]
            let label = UILabel()
            let labelHora = UILabel()
            let img = UIImageView()
            let url:NSURL? = NSURL(string:currentArticleToDisplay.icono[estado!]!)
            let imageRequest = NSURLRequest(URL: url!)
            // Fire off the request to download it
            NSURLConnection.sendAsynchronousRequest(imageRequest, queue: NSOperationQueue.mainQueue(), completionHandler: {(response, data, error) in
                // Assign the data to the imageview
                img.image = UIImage(data: data!)
            label.text = currentArticleToDisplay.temperatura[valorArray]
            labelHora.text = valorArray
            let vista = UIView()
            vista.frame = CGRectMake(0, 0, 100, 50.0)


Currently it's like this:

What is inside the blue circle would be an item. what I want is that instead of leaving the sun, the temperature and the time in line, leave one under another one

Thanks in advance!

asked by joserock85 24.06.2016 в 10:37

3 answers


Do not use external libraries for such a simple task. The best way to organize what you need is as follows:

In this way, it will be all native and you will have the maximum control over the sizes, AutoLayout , etc. The cell of UICollectionView make it either in a XIB apart or in the StoryBoard directly.

answered by 29.06.2016 / 00:01

I think you should use a UICollectionView , I do not see the need to use a separate library, you can create a cell in the storyboard and organize the elements vertically or the way you want and place that collectionView inside the UIView or UITableView.

answered by 28.06.2016 в 23:41

I would use a UICollectionView only with different cell types. Care must be taken when interacting with various components such as UICollectionView within a UITableView by performance issues.

Even so, what you would never do is use a library to implement the view you want to do, since UIKit provides native components for it.

answered by 24.04.2017 в 17:26