screen shotのように、UIViewController
に基づいてUICollectionView
を実装します。UICollectionViewのセルの境界線とサイズ変更
は、ここに私のコードです:
class SettingViewController: BaseViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 3
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! SettingCollectionViewCell
cell.backgroundColor = UIColor.greenColor()
cell.lb.text = "Something"
cell.img.image = UIImage(named: "setting")
cell.layer.borderColor = UIColor.lightGrayColor().CGColor
cell.layer.borderWidth = 1
return cell;
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let screen = UIScreen.mainScreen().bounds
return CGSize(width: CGFloat(screen.width/3 - 10), height: 120)
}
}
、これが結果です:result :)))私は実際に私の心をlosed
!
私はfunc sizeForItemAtIndexPath
を実装してセルのサイズを変更しましたが、各セルの間隔は同じで、同じ幅を持たず、設計上の境界をどのように取得するのか分かりませんでした。
私を助けてください!セルフサイジング電池用
CGFloat((screen.width-(3 * 10))/ 3) –
私は試しましたが、何も起こりません –