- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在我的文本字段中有一个图标,并且我正在使用 setLeftView 属性。我现在的代码是
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 26, tb_teamA_playerA.bounds.size.height)];
leftView.contentMode = UIViewContentModeScaleAspectFit;
[leftView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed : @"person_26" ]]];
[tb_teamA_playerA setLeftView :leftView];
[tb_teamA_playerA setLeftViewMode: UITextFieldViewModeAlways];
这就是结果。
最左边的图像是一个单独的 UIImageView,具有相同的图像集和比例设置为 ScaleAspectFit。所以我希望这两张图片的大小和比例相同,但事实并非如此?!
最佳答案
您正在使用 UIViewContentModeScaleAspectFit,因此图像将适合 UITextField 的大小。我认为您应该使用 UIViewContentModeScaleAspectFill,如果您对尺寸有疑问并且两个图像的尺寸仍然不同,您应该调整图像的大小。
以下内容来自Doc
UIViewContentModeScaleToFill
Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.
UIViewContentModeScaleAspectFit
Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.
UIViewContentModeScaleAspectFill
Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.
关于ios - 用于 UITextfield setLeftView 的 xcode UIView ScaleAspectFit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26957358/
我有在 UIImageView 中显示的 UIImage。 UIImageView 有 contentMode = .scaleAspectFit 属性(property)。 UIImages 在 U
我的 Swift 代码中有这个 ImageView let background_image: UIImageView = { let im = #imageLiteral(resourceN
在我的应用中,我允许用户以纵向模式录制视频。我在应用程序中使用它,这很好。但是,我正在实现一项功能以在 Instagram 上分享视频,其中视频必须是方形的。 将视频裁剪成正方形,比方说中间部分,是一
我很难理解 UIViewContentModeScaleAspectFit 的工作原理。我正在开发应用程序,我希望图像应该以图像周围必须有空白区域的方式重新绘制,并且图像必须设置在 ImageView
我想在 UIImageView 中显示图像。图像比 UIImageView 大,所以我这样设置 contentMode: previewImageView.contentMode = .scaleAs
我有一个 UIImageView,其中图像是用给定的 url 设置的。然后,我将内容模式设置为 Scale Aspect Fit。这工作正常,但是当图像应该直接位于屏幕顶部时,图像前后有大量空白。 我
这里是 an image我的问题。我的问题是我的 UIImageView 右侧有一个很小的空白空间,它被限制在我的 View Controller 的 View 中。由于我设置的背景,它是绿色的,并且
我有几个部分透明的 PNG 叠加层,以在 View 中相互叠加显示。覆盖的数量因运行时条件而异。我想在 Swift 中创建 UIImageView 实例并将它们添加到 View 中。 在 Storyb
我在 IB 中创建了一个内容模式为 Aspect Fit 的 UIImageView。然后我从 URL 将大图像加载到该 View 。 @IBOutlet weak var pictureView:
我有一个带有 CustomCell 的表格,在绘制单元格时,我创建了一个 UIImageView 并将其作为 subview 添加到 scrolView。该图像还将其 contentMode 设置为
我正在堆栈 View 中遮盖图像,由于某些奇怪的原因,我的 mask 未与图像正确对齐/调整大小。 这里演示了当我在堆栈 View 中动态添加该图像的实例时所发生的情况,同时每个 subview 在其
我想在我的文本字段中有一个图标,并且我正在使用 setLeftView 属性。我现在的代码是 UIView *leftView = [[UIView alloc] initWithFrame:
我有 UITableView,其中每个单元格上有一个具有相同 View (仅不同内容)的 UIStackView。(tableView 的单元格如下所示) View 由上面的 UIImageView
我在 UIImageView 中有一张图片: imageView.contentMode = .scaleAspectFit imageView.backgroundColor = .r
我有一个 UIButton 和一个 UIImage。我正在调用 myButton.setBackgroundImage 但这会导致按钮拉伸(stretch)。奇怪的是,按钮宽度是恒定的,但高度却向下拉
我是一名优秀的程序员,十分优秀!