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