美文网首页
UITextField共用一个图片问题

UITextField共用一个图片问题

作者: 张俊凯 | 来源:发表于2018-08-05 15:54 被阅读2次

    问题代码

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片"]];
        
        UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectZero];
        [self.view addSubview:text1];
        text1.rightViewMode = UITextFieldViewModeAlways;
        text1.rightView = imageView;
        
        UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectZero];
        [self.view addSubview:text2];
        text2.rightViewMode = UITextFieldViewModeAlways;
        text2.rightView = imageView;
    

    两个textField的rightView共用一个imageView对象,程序会无法运行,必须为不同的对象
    改正后代码

    UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectZero];
        [self.view addSubview:text1];
        text1.rightViewMode = UITextFieldViewModeAlways;
        text1.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片"]];
        
        UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectZero];
        [self.view addSubview:text2];
        text2.rightViewMode = UITextFieldViewModeAlways;
        text2.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片"]];
    

    相关文章

      网友评论

          本文标题:UITextField共用一个图片问题

          本文链接:https://www.haomeiwen.com/subject/yxmbvftx.html