我的问题是我创建了一个文本字段,其中leftviewmode是一个图像,占位符位于文本字段中间的某处,文本编辑应该在用户开始输入时开始。那么如何从占位符所在的文本域中间开始我的文本。我无法在imageview中设置leftviewmode,因为我已经在那里添加了图像。我该怎么办?
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"a_point30"]];
image.frame = CGRectMake(0, 0, image.image.size.width, image.image.size.height-10);
self.enterSource.leftViewMode = UITextFieldViewModeAlways; self.enterSource.leftView = image;
例如短信应该从hello world占位符开始。
答案 0 :(得分:1)
你可以这样做,
UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgName]];
imgView.frame = CGRectMake(0.0, 0.0, dropDown.image.size.width+10.0, dropDown.image.size.height);
imgView.contentMode = UIViewContentModeLeft;
textField.leftView = imgView;
textField.leftViewMode = UITextFieldViewModeAlways;
答案 1 :(得分:0)
在 Swift 2.2.1 中,它将是这样的:
let imageView = UIImageView(image: UIImage(named: "ImageName"))
imageView.frame = CGRectMake(0.0, 0.0, imageView.image!.size.width + 10, imageView.image!.size.height)
imageView.contentMode = UIViewContentMode.Left
textField.leftView = imageView
textField.leftViewMode = UITextFieldViewMode.Always