Iphone uiImageView显示UICollectionViewCell中图像之间的边界

Iphone uiImageView显示UICollectionViewCell中图像之间的边界,iphone,objective-c,uiimageview,uicollectionview,Iphone,Objective C,Uiimageview,Uicollectionview,我们有一行139x127图像,这些图像在集合视图单元格中显示,带有边框。我们尝试了UIViewContentModeScaleAspectFill(和Fit),但它仍然显示边框 代码如下: //uicollectionviewcell (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code self = [super initW

我们有一行139x127图像,这些图像在集合视图单元格中显示,带有边框。我们尝试了UIViewContentModeScaleAspectFill(和Fit),但它仍然显示边框

代码如下: //uicollectionviewcell

(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
    self = [super initWithFrame:frame];
    if (self) {

        // Initialization code
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"ProfilePhotoCell" owner:self options:nil];

        if ([arrayOfViews count] < 1) {
            return nil;
        }

        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
            return nil;
        }

        self = [arrayOfViews objectAtIndex:0];

    }

    [self.imageView setContentMode:UIViewContentModeScaleAspectFill];

    return self;

}
return self;
}

 // uicollectionview/viewcontroller
// 1
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
// 2
CGSize retval = CGSizeMake(100, 66);
return retval;
}

  // 3
 - (UIEdgeInsets)collectionView:
 (UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(20, 0, 0, 0);
}
(id)initWithFrame:(CGRect)frame
{
self=[super initWithFrame:frame];
如果(自我){
//初始化代码
self=[super initWithFrame:frame];
如果(自我){
//初始化代码
NSArray*ArrayOfView=[[NSBundle mainBundle]loadNibNamed:@“ProfilePhotoCell”所有者:自选项:nil];
如果([arrayOfViews计数]<1){
返回零;
}
如果(![[arrayOfViews objectAtIndex:0]是类的种类:[UICollectionViewCell类]]){
返回零;
}
self=[ArrayOfView对象索引:0];
}
[self.imageView setContentMode:UIViewContentModeScaleAspectFill];
回归自我;
}
回归自我;
}
//uicollectionview/viewcontroller
// 1
-(CGSize)collectionView:(UICollectionView*)collectionView布局:(UICollectionViewLayout*)collectionViewLayout大小FormiteIndeXPath:(NSIndexPath*)indexPath{
// 2
CGSize-retval=CGSizeMake(100,66);
返回返回;
}
// 3
-(UIEDGEINSET)集合视图:
(UICollectionView*)collectionView布局:(UICollectionViewLayout*)collectionViewLayout插入部分索引:(NSInteger)部分{
返回UIEdgeInsetsMake(20,0,0,0);
}

这里是一个截图:

UICollectionView的collectionViewLayout属性发生了什么变化?我猜UICollectionView正在填充它显示的单元格。

出于调试目的,我发现通过暂停应用程序并运行来使用
LLDB
是无价的

po [[UIWindow keyWindow] _autolayoutTrace]
这将为您提供指向每个视图对象的指针。然后我会跑

po [0xabcd123 constraints]
…查看是否在运行时添加了您不知道的自动约束。此外,您还可以获取单元格和视图的帧大小,并查看它们是否匹配。您可能需要以编程方式删除自动约束,并应用将视图固定到单元格的新约束。我在将视图单元格从一个视图“翻转”到另一个视图时遇到了一些这样的情况

别忘了关闭init或IB中的自动约束

[self.imageview setTranslatesAutoresizingMaskIntoConstraints:NO];

祝你好运

你想要什么。。。带边框或不带边框的图像在UIEDGEINSETSMAKE(0,0,0,0)之间没有间距/填充的图像;不,我早些时候试过,但没用。奇怪的是,增加“顶”、“底”、“左”和“右”值确实会增加它们之间的间距,即使我使用了负值,但仍然无法删除图像之间的间距。请将sizeForItemAtIndexPath中的值调整为320.0/3.0作为宽度