UITextfield中的图像有多大

时间:2015-06-17 06:27:21

标签: ios objective-c iphone uiimage uitextfield

我有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}},x2x像素显示。

3 个答案:

答案 0 :(得分:2)

来自documentation

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=0y=0width = width of the imageheight = height of the image

答案 2 :(得分:0)

您可以根据需要设置任何分辨率的任何图像。还请在代码的最后一行之前添加以下行,以使图像可见。

[name setLeftViewMode:UITextFieldViewModeAlways];