我正在创建一个iOS应用程序,我需要在特定位置添加图像(左上角),我应该如何将图像添加到特定位置的文本字段?将图像添加到ios中特定位置的UITextFields
-3
A
回答
1
UIImageView* usernameIconImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 42, 42)];
usernameIconImage.image = [UIImage imageNamed:@"username.jpg"];
UIView* usernameIconContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 42, 42)];
usernameIconContainer.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
[usernameIconContainer addSubview:usernameIconImage];
self.userIDField.leftViewMode = UITextFieldViewModeAlways;
self.userIDField.leftView = usernameIconContainer;
0
您可以通过使用UITextField
leftView
属性,在这里你可以轻松地分配一个UIImageView
看到下面的代码中的UITextField
UITextField *textField = [[UITextField alloc] init];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage"]];
[textField setLeftView:imageView];
0
可以达到这个添加的ImageView为leftView。
self.textField.leftViewMode=UITextFieldViewModeAlways;
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 30.0)];
imageView.image=YOURIMAGE;
self.textField.rightView=imageView;
我希望它有帮助。
干杯。
+0
我希望你的意思是'self.textField.leftView = imageView;' – GenieWanted
0
UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, self.yourTextField.frame.size.height)]; // you can choose your desired width
[leftImageView setBackgroundColor:[UIColor clearColor]];
[leftImageView setImage:[UIImage imageNamed:@"test.png"]];
yourTextField.leftView = leftImageView;
+0
谢谢你回复我 – madhuiOS
相关问题
- 1. 将图像定位到特定位置
- 2. 将图像添加到特定的li
- 3. 将多个图像添加到位于特定位置的Word文档OpenXML
- 4. IOS-CoreImage将一个图像复合到另一个图像的特定位置
- 5. 将特定位置的图像绘制到现有图像上
- 6. 将图像添加到Word文档的指定位置
- 7. 如何将多个UITextFields添加到iOS 7中的UIAlertView?
- 8. 如何在iOS中将3个UITextFields添加到UIAlertView中?
- 9. 将图片添加到Google iOS SDK中的位置
- 10. 将图像/图标添加到chart.js中的特定坐标
- 11. 将列添加到MSSQL服务器中的特定位置
- 12. 将iframe添加到HTML中的特定位置使用jquery
- 13. 将变量添加到特定位置的数组中
- 14. 将新变量添加到数据框中的特定位置
- 15. 将Android ImageButton添加到Android中的特定位置
- 16. 将元素添加到列表中的特定位置
- 17. 如何将QAction添加到QToolBar中的特定位置
- 18. 如何将列添加到ListView中的特定位置?
- 19. 将字符串添加到Postgres中的特定位置
- 20. 是否可以将NSStatusItem添加到NSStatusBar中的特定位置?
- 21. 将图像拖放到Android中的特定位置
- 22. 添加图像作为按钮为特定位置(的Actionscript 3.0)
- 23. 将背景上的位置图像置于特定位置
- 24. 将特定图像添加到Java中的JPanel中
- 25. 如何将图像添加到位图
- 26. MKMapView添加特定位置
- 27. 将图像添加到QGraphicsScene中的某个位置
- 28. php将图像添加到另一个图像,精确定位
- 29. 特定图像位置
- 30. 强制图像到特定位置
欢迎堆栈溢出。请阅读[Stack Overflow:How to ask](http://stackoverflow.com/questions/how-to-ask)和[Jon Skeet的问题清单](http://msmvps.com/blogs/jon_skeet/archive/2012) /11/24/stack-overflow-question-checklist.aspx)来找出如何提出一个很好的问题,这将产生很好的答案。 –
k谢谢你这么多 – madhuiOS