• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
iOS 8, Xcode 6 and UICollectionView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iOS 8, Xcode 6 and UICollectionView


  • Subject: iOS 8, Xcode 6 and UICollectionView
  • From: John Tsombakos <email@hidden>
  • Date: Tue, 29 Jul 2014 11:43:03 -0400

I wanted to play with a UICollectionView, so I translated the code in this NSScreencast episode (thanks, Ben :) to Swift :

http://nsscreencast.com/episodes/46-fun-with-uicollectionview

I got it all to build and run, but the resulting collection view doesn’t look the same as when the original ObjC code is run on the iOS 7 simulator.  The cells are too big (showing only 5 cells across). I’m pretty sure it has something to do with auto layout(?) and size classes, but no matter what I fiddle with, it’s not working. Even stranger, when rotating the simulator, the cells aren’t lined up at all.

I’m going to look through the UICollectionView docs on iOS 8, but if anyone has come across it, that’d be great. I’m including the Swift version of the UICollectionViewCell subclass, just for reference.

Thanks!


//NumberCell.swift

import UIKit

class NumberCell: UICollectionViewCell {

    var label: UILabel!

    init(frame: CGRect) {
        super.init(frame: frame)
        self.label = UILabel(frame: frame)
        self.autoresizesSubviews = true
        self.label.autoresizingMask = UIViewAutoresizing.FlexibleWidth & UIViewAutoresizing.FlexibleHeight
        self.label.font = UIFont.boldSystemFontOfSize(42)
        self.label.textAlignment = NSTextAlignment.Center
        self.label.adjustsFontSizeToFitWidth = true

        self.addSubview(self.label)

        self.setNumber(0)
    }

    func setNumber(number: Int) {
        self.label.text = "\(number)"
    }
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Prev by Date: Re: iOS 8 beta 4 messes with my TextView
  • Next by Date: Re: OS X play a video?
  • Previous by thread: Re: How to constrain a UISlider in a UIToolbar?
  • Next by thread: Autolayout frustrations with NSOutlineView
  • Index(es):
    • Date
    • Thread