Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Collectionview que muestra diferentes celdas con diferentes dispositivos iPad para un calendario personalizado

Estoy tratando de crear un calendario personalizado en mi aplicación y agregué el siguiente código.

 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: collectionView.frame.size.width/7, height: 36) }

Pero en diferentes dispositivos iPad, los días de la semana muestran más de 7 y algunos iPad muestran 5 días de la semana. Está cambiando el tamaño de la celda según el tamaño de la pantalla. Pero quiero agregar & días para todos los anchos de pantalla de iPad. Entonces probé lo siguiente

 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { if UIDevice().userInterfaceIdiom == .pad { if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && (UIScreen.main.bounds.size.height == 1366 || UIScreen.main.bounds.size.width == 1366)) { print("iPad Pro : 12.9 inch") return CGSize(width: collectionView.frame.width/7 + 20, height: 36) } else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && (UIScreen.main.bounds.size.height == 1024 || UIScreen.main.bounds.size.width == 1024)) { print("iPad 2 || iPad Pro : 9.7 inch || iPad Air/iPad Air 2 || iPad Retina ") return CGSize(width: collectionView.frame.width/7 - 5, height: 36) } else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && (UIScreen.main.bounds.size.height == 1180 || UIScreen.main.bounds.size.width == 1180)) { print("iPad Air 4th gen") return CGSize(width: collectionView.frame.width/7 + 5, height: 45) } else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && (UIScreen.main.bounds.size.height == 1194 || UIScreen.main.bounds.size.width == 1194)) { print("iPad Pro 11") return CGSize(width: collectionView.frame.width/7 + 5, height: 45) } else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && (UIScreen.main.bounds.size.height == 1112 || UIScreen.main.bounds.size.width == 1112)) { print("iPad Air 3") return CGSize(width: collectionView.frame.width/7, height: 45) } else { print("iPad 3") return CGSize(width: collectionView.frame.width/7, height: 45) } } return CGSize(width: collectionView.frame.width/7, height: 45) }

Para usar esto, la mayoría de los dispositivos iPad obtienen exactamente 7 días de celda. Pero algunos dispositivos (iPad de 5.ª, 6.ª y 7.ª generación) con un ancho de pantalla de 1024 siguen mostrando 6 días a la semana. Probé con el simulador.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Obtuve la solución perfecta con el siguiente código.

func collectionView(_ collectionView: UICollectionView, diseño collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: (self.contentView.frame.width - 173)/7, height: 45) }

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!