我有UITextfield
这样:
UITextfield *name = [[UITextField alloc] initWithFrame:CGRectMake(30, 210, 100, 34)];
name.borderStyle = UITextBorderStyleRoundedRect;
name.backgroundColor = [UIColor whiteColor];
name.font = [UIFont systemFontOfSize:12];
name.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
如果我有以下UITextfield
设置,那么UIImage
所支持的点数是多少?是34乘34还是稍小?我知道,如果34分是34分,我将.png
s 34x34 , 68x68 和 92x92 {{{ 1}},x
和2x
像素显示。
答案 0 :(得分:2)
The left overlay view is placed in the rectangle returned by the
leftViewRectForBounds: method of the receiver. The image associated
with this property should fit the given rectangle. If it does not fit,
it is scaled to fit. If you specify a control for your view, the
control tracks and sends actions as usual.
这意味着您可以更改leftView的大小。
在iOS 8.3上,“leftViewRectForBounds:”值基于leftView的大小。如果我使用尺寸为300x300的leftView,则框架将为(0,-125,300,300)。如果我使用尺寸为30x30的视图,那么框架将是(0,10,30,30) 我的textField的框架是(0.0,0.0,300.0,50.0)。
答案 1 :(得分:1)
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
它的框架将是x=0
,y=0
,width = width of the image
,height = height of the image
答案 2 :(得分:0)
您可以根据需要设置任何分辨率的任何图像。还请在代码的最后一行之前添加以下行,以使图像可见。
[name setLeftViewMode:UITextFieldViewModeAlways];