0
我遇到了一个无法解决2天的问题。在将服务器映像插入到服务器映像中之前,我将它们在客户端上剪切以适应屏幕。一切都很好,但图像随机高度变化。现在高度是独立计算的 - 与宽度成正比。 普通影像:tableviewcell里面的图片大小调整
坏形象
因为我动态我靠所有的细胞不同的设备我不能明确要求的UIImageView。
我调整大小功能:
-(UIImage *)resizeImage :(UIImage *)theImage :(CGSize)theNewSize {
UIGraphicsBeginImageContextWithOptions(theNewSize, NO, 1.0);
CGFloat height = theImage.size.height;
CGFloat newHeight = 0;
newHeight = (theNewSize.width * height)/theImage.size.width;
newHeight = floorf(newHeight);
NSLog(@"new height image %f", newHeight);
[theImage drawInRect:CGRectMake(0, 0, theNewSize.width, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
内layoutSubviews:
if(device == thisDeviceClass_iPhone5) {
[self.imageView setFrame:CGRectMake(0,0, 320, 255)]; //180
offset = 0;
padding = 5;
} else if(device == thisDeviceClass_iPhone6){
[self.imageView setFrame:CGRectMake(0,0, 375, 255)]; //211
offset = 25;
} else if(device == thisDeviceClass_iPhone6plus) {
[self.imageView setFrame:CGRectMake(0,0, 414, 255)]; //233
offset = 40;
}
是的,我知道这是不好的代码,这是一个临时解决方案。就像我没有指定图像的确切尺寸一样,它会独立移动,并在自定义单元类中传递屏幕的尺寸,我不知道如何。没有变量self.view。 ... – user2759544
我安装了这个contentMode,但不能帮助图像扭曲,并理解为什么我不能拉紧。 – user2759544
您是否将imageView的“剪辑子视图”设置为YES?包括 – null