Issue in UITextField add inside UIImageView in iPhone?

半腔热情 提交于 2019-12-06 16:46:21

问题


Currently i am working in iPhone app, Using UIImageView to set a background image on the screen, then add UITextField inside the UIImageView, then i run the app, the UITextField cannot enabled, How to enable this? please help me

Thanks in Advance

I tried this:

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView.image=[UIImage imageNamed:@"2ndscreenback.png"];

Daystext =[[UITextField alloc]initWithFrame:CGRectMake(57, 122, 171, 31)];
Daystext.borderStyle=UITextBorderStyleRoundedRect;
Daystext.delegate=self;
Daystext.userInteractionEnabled=YES;
[imageView addSubview:Daystext];
[self.view addSubview:imageView];

回答1:


Just add below line in your code

imageView.userInteractionEnabled = YES;

Means like this

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView.image=[UIImage imageNamed:@"2ndscreenback.png"];

Daystext =[[UITextField alloc]initWithFrame:CGRectMake(57, 122, 171, 31)];
Daystext.borderStyle=UITextBorderStyleRoundedRect;
Daystext.delegate=self;
Daystext.userInteractionEnabled=YES;
imageView.userInteractionEnabled = YES;
[imageView addSubview:Daystext];
[self.view addSubview:imageView];



回答2:


try like this,

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView.image=[UIImage imageNamed:@"2ndscreenback.png"];
imageView.userInteractionEnabled=YES;
[self.view addSubview:imageView];

Daystext =[[UITextField alloc]initWithFrame:CGRectMake(57, 122, 171, 31)];
Daystext.borderStyle=UITextBorderStyleRoundedRect;
Daystext.delegate=self;

[imageView addSubview:Daystext];

you can get the textfield on imageview....




回答3:


Try this:

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView.image=[UIImage imageNamed:@"2ndscreenback.png"];

Daystext =[[UITextField alloc]initWithFrame:CGRectMake(57, 122, 171, 31)];
[self.view addSubview:imageView];
Daystext.borderStyle=UITextBorderStyleRoundedRect;
Daystext.delegate=self;
Daystext.userInteractionEnabled=YES;
[self.view addSubview:Daystext];



回答4:


I think it's better to set background image for your UITextFild like this:

myTextField.borderStyle = UITextBorderStyleNone;
myTextField.background = [UIImage imageNamed:@"back.png"];

or like this

UIImageView *myView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"back.png"]];
[myTextField  setRightView:myView];
[myTextField  setRightViewMode:UITextFieldViewModeAlways];



回答5:


UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView.image=[UIImage imageNamed:@"2ndscreenback.png"];

Daystext =[[UITextField alloc]initWithFrame:CGRectMake(57, 122, 171, 31)];
[self.view addSubview:imageView];
Daystext.borderStyle=UITextBorderStyleRoundedRect;
Daystext.delegate=self;
Daystext.editable = YES;
Daystext.userInteractionEnabled=YES;
[self.view addSubview:Daystext];

Try this. Hope it works for u !!!



来源:https://stackoverflow.com/questions/12346269/issue-in-uitextfield-add-inside-uiimageview-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!