Ios UIExtField setLeftView的xcode UIView ScaleSpectFit
我想在我的文本字段中有一个图标,我正在使用setLeftView属性。 我现在的代码是Ios UIExtField setLeftView的xcode UIView ScaleSpectFit,ios,objective-c,xcode,uiimage,uitextfield,Ios,Objective C,Xcode,Uiimage,Uitextfield,我想在我的文本字段中有一个图标,我正在使用setLeftView属性。 我现在的代码是 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 26, tb_teamA_playerA.bounds.size.height)]; leftView.contentMode = UIViewContentModeScaleAspectFit; [leftView setBackground
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,具有相同的图像集,并且比例设置为ScaleSpectFit。
所以我原以为这两张照片的大小和比例是一样的,但事实并非如此 您正在使用UIViewContentModeScaleSpectFit,因此图像将适合UITextField的大小。 我认为您应该使用UIViewContentModeScaleAspectFill,如果您对大小有一些问题,并且两个图像的大小仍然不相同,您应该调整图像的大小 以下是来自 UIViewContentModeScaleToFill 如有必要,可通过更改内容的纵横比来缩放内容以适应其自身的大小 UIViewContentModeScaleAspectFit 通过保持纵横比,缩放内容以适合视图的大小。视图边界的任何剩余区域都是透明的 UIViewContentModeScaleAspectFill 缩放内容以填充视图的大小。可以剪裁部分内容以填充视图的边界