UITableView具有方法rectForRowAtIndexPath:,但UICollectionView中不存在该方法.我正在寻找一种很好的方法来获取单元格的边框,也许我可以在UICollectionView上添加一个类别.

推荐答案

我找到的最好的方法是这样做:

Objective-C

UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath];

Swift

let attributes = collectionView.layoutAttributesForItem(at: indexPath)

然后您可以通过attributes.frameattributes.center访问该位置

Ios相关问答推荐

Nomb iOS 17.4.0中崩溃

在带有可编码的SWIFT5中,可以轻松处理以美元符号开头的JSON密钥,例如$DATE";

Flutter 翼项目.升级到XCode 15.0.1`pod install`抛出错误FlutterMacOS.podspec.json 3.13.2的ParserError

为什么 Firebase Messaging 配置对于 IOS native 和 Flutter iOS 不同?

AppCenter 错误:/usr/bin/xcodebuild 失败,返回码:65

clipShape swift的三元

有哪些可靠的机制可以防止 CoreData CloudKit 中的数据重复?

如何将 ImageView 放置在 UIView 的中心?

iOS 中的 [Class new] 和 [[Class alloc] init] 有什么区别?

在 Swift 中按下返回键时在文本字段之间切换

如何设置imageView的圆角半径?

每次运行后,Xcode 6 都会在 iOS8 模拟器中重命名我的应用程序目录.

检测 iPhone/iPad/iPod touch 的 colored颜色 ?

如何使用 swift 显示 .svg 图像

如何在键盘上方添加工具栏?

以编程方式创建按钮并设置背景图像

文本未包含在 swift UI 中

如何为 NSDate 添加一个月?

我的应用程序因使用广告支持框架而被拒绝.哪个图书馆负责?

你如何以编程方式从视图控制器中画一条线?