- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个大小为 366 x 375 的 UIImageView
(由 NSLog
语句确认)和一个大小为 400 的 UIImage
x 600(再次通过日志语句确认)。我已尝试设置 contentMode
以保持图像的纵横比,但当我运行我的应用程序时,图像总是失真。
我尝试将 UIView
的内容模式依次设置为 UIViewContentModeScaleAspectFit
和 UIViewContentModeScaleAspectFill
。在这两种情况下,照片仍然以相同的方式扭曲。我还尝试了 UIContentModeLeft
,只是为了好玩,这也导致了同样的扭曲演示。我的理解是这三种模式应该呈现出截然不同的图像。
我已经通过 View Controller 代码完成了 ctrl-f
,但是只出现了一次 contentMode
,这是我设置属性的地方。是否还有其他我应该查看的属性可能会产生干扰?
这里是设置 ImageView 和伴随图像的代码。这是整个项目中唯一引用 ImageView 的代码。此外,我没有使用任何类型的自动布局功能,尽管我不明白为什么这会影响纵横比和内容模式。
NSData *imageData = [NSData dataWithContentsOfURL:filePath];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.height*.11, self.width, self.height*.55)];
self.imageView.image = [UIImage imageWithData:imageData];
NSLog(@"Image height and width are %f and %f", self.imageView.image.size.height, self.imageView.image.size.width);
NSLog(@"imageview height and width are %f and %f", self.imageView.frame.size.height, self.imageView.frame.size.width);
[self.view addSubview: self.imageView];
为什么 contentMode
不影响我的图像显示方式,我该如何解决这个问题?最后,我想使用缩放方面填充选项,这样 ImageView 中就没有空白空间,但同时也保留了方面。
最佳答案
试试这个
self.imageView.contentMode = UIViewContentModeScaleAspectFill
编辑
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.height*.11, self.width, self.height*.55)];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.image = [UIImage imageWithData:imageData];
NSLog(@"Image height and width are %f and %f", self.imageView.image.size.height, self.imageView.image.size.width);
NSLog(@"imageview height and width are %f and %f", self.imageView.frame.size.height, self.imageView.frame.size.width);
[self.view addSubview: self.imageView];
分配imageview后设置内容模式
关于ios - 设置 UIImageView contentMode 显示无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32382566/
我正在尝试将 UINavigationBar 的背景设为图像,但该图像并不是栏的确切大小。由于某种原因,我似乎无法正确设置栏的 contentMode 。这是我的代码: override func v
我正在尝试将我的 UITableView 设置为较小的高度并设置了 contentMode,但是,我无法让它滚动……它只是减小了尺寸。我做错了什么? [self.tableView setConte
所以我有这个 UIImageView ,上面有一个图像。当我使用普通的 iPhone 显示屏时,它在 UIImageView 内完全按照预期显示 - 在 UIImageView 范围内,问题是当我使用
我正在绘制一堆 UIImageView (100x100) 作为菜单项。每个都有自己的图像,有些大于 100x100,有些更小。默认情况下,具有较大图像的 imageView 会按比例缩小以很好地适应
let assests : PHAsset = self.asset[indexPath.item] as! PHAsset PHImageManager.defaultManager().r
我正在尝试将 UIImageView 的图像属性设置为我正在使用 CoreImage 进行模糊处理的图像。该代码与未过滤的图像完美配合,但是当我将背景图像设置为过滤后的图像时,contentMode
我完全被这个尺寸错误难住了。我的 View 布局中有一个 UIImageView 和一个 UITableView。 UIImageView 在 IB 中设置为 Aspect Fit,当我使用 IB 设
我有一个大小为 366 x 375 的 UIImageView(由 NSLog 语句确认)和一个大小为 400 的 UIImage x 600(再次通过日志语句确认)。我已尝试设置 contentMo
我正在使用 AlamofireImage,我注意到它具有设置所需图像的内容类型的功能。但是,我看不到设置占位符图像本身的内容类型的可能性。 例如,现在在我的 cellForRow 方法中我正在做: l
我有以下代码,适用于旧版 IOS 应用程序,但现在在 xcode 9 中不再适用: 我得到的错误是: 'ContentMode' is not a member type of 'UIView' 代码
我正在使用 CIFilter 为图像添加滤镜。过滤图像后的结果图像大小如下:CGRectMake(10, 10, 70, 70)。我无法将生成的图像内容模式设置为 ScaleAspectFill。这是
我使用 [myButton setImage:forState:]; 为我的 UIButton 设置了一个 UIImage我使用 [[myButton imageView] setContentMod
在 Obj-C 中 imageView.contentMode = UIViewContentModeScaleAspectFill; 将设置 contentMode。 为什么 imageView.c
我对 UIImageView 显示图像的方式感到非常失望。 我有以下代码: UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRe
我有一个 Collection View 。我在 Collection View 的每个单元格上放置了一个 ImageView。然后我将 ImageView 的 contentMode 设置为 Sca
在照片框架中,我正在尝试查看使用 PHImageManager 中的 RequestImageFor Asset 方法的教程。 这是一段代码: let asset:PHAsset = self
我很难理解 UIViewContentModeScaleAspectFit 的工作原理。我正在开发应用程序,我希望图像应该以图像周围必须有空白区域的方式重新绘制,并且图像必须设置在 ImageView
当我将图像(通过 Storyboard )添加到按钮图像内容模式时不起作用。当我通过图像插入和另一台设备(iPad)上的标题插入修复它(iPhone)时,它失去预期比率?我该如何修复它?? 最佳答案
我正在尝试创建一个小示例来解释 UIImageView 的 contentMode (scaleAspectFill)。 一切都是编码的,没有使用 Storyboard。检查了很多有助于解释这一点的例
我一直在关注 Ray Wenderlics 关于如何创建基本绘图应用程序的教程。 除了在 uiimageview 上绘制内容模式更改时,我让它工作得很好。 我在 Storyboard 中将它设置为 a
我是一名优秀的程序员,十分优秀!