gpt4 book ai didi

ios - 用于 UITextfield setLeftView 的 xcode UIView ScaleAspectFit

转载 作者:行者123 更新时间:2023-11-28 21:54:46 26 4
gpt4 key购买 nike

我想在我的文本字段中有一个图标,并且我正在使用 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];

这就是结果。

enter image description here

最左边的图像是一个单独的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com