美文网首页iOS知识
ios13下 UITextField 设置leftView/ri

ios13下 UITextField 设置leftView/ri

作者: 燃_火 | 来源:发表于2019-11-30 11:12 被阅读0次
    UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    imagev.image = [UIImage imageNamed:@""];
    imagev.contentMode = UIViewContentModeCenter;
    UITextField *txtSearch = [[UITextField alloc] init];
    txtSearch.leftView = imagev;
    txtSearch.leftViewMode = UITextFieldViewModeAlways;
    

    这是以往设置leftView的方法,但是在iOS13下,发现是无效的,解决的方法很简单,将UIImageView改为UIView即可:

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    UITextField *txtSearch = [[UITextField alloc] init];
    txtSearch.leftView=view;
    txtSearch.leftViewMode = UITextFieldViewModeAlways;
    

    相关文章

      网友评论

        本文标题:ios13下 UITextField 设置leftView/ri

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