Issue in UITextField add inside UIImageView in iPh

2019-04-17 09:45发布

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];

5条回答
beautiful°
2楼-- · 2019-04-17 10:33
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 !!!

查看更多
一夜七次
3楼-- · 2019-04-17 10:37

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];
查看更多
Juvenile、少年°
4楼-- · 2019-04-17 10:39

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....

查看更多
Anthone
5楼-- · 2019-04-17 10:41

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];
查看更多
对你真心纯属浪费
6楼-- · 2019-04-17 10:42

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];
查看更多
登录 后发表回答