UITextField共用一个图片问题

2018-08-05  本文已影响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:@"图片"]];
上一篇下一篇

猜你喜欢

热点阅读