【问题标题】:Issue in UITextField add inside UIImageView in iPhone?在 iPhone 的 UIImageView 中添加 UITextField 中的问题?
【发布时间】:2012-09-10 06:20:30
【问题描述】:

目前我正在使用 iPhone 应用程序,使用 UIImageView 在屏幕上设置背景图像,然后在 UIImageView 中添加 UITextField,然后我运行应用程序,UITextField 无法启用,如何启用此功能?请帮帮我

提前致谢

我试过了:

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

【问题讨论】:

  • 写 Daystext.editable = YES;

标签: iphone ios uiimageview uitextfield


【解决方案1】:

只需在代码中添加以下行

imageView.userInteractionEnabled = YES;

这样的意思

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】:

    试试这样,

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

    您可以在 imageview 上获取文本字段....

    【讨论】:

      【解决方案3】:

      试试这个:

      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】:

        我认为最好像这样为你的 UITextFild 设置背景图片:

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

        或者像这样

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

        试试这个。希望对你有用!!!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-10-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-22
          • 1970-01-01
          相关资源
          最近更新 更多