美文网首页
iOS中实现键盘右上角完成按钮

iOS中实现键盘右上角完成按钮

作者: 缘來諟夢 | 来源:发表于2020-12-16 15:49 被阅读0次

    继承UITextField,重写drawRect方法

    - (void)drawRect:(CGRect)rect {
        [superdrawRect:rect];
        UIToolbar *bar = [[UIToolbaralloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,44)];
        UIButton *button = [[UIButtonalloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 60, 7,50, 30)];
        [button setTitle:@'完成'forState:UIControlStateNormal];
        [button setTitleColor:[UIColorredColor] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColorredColor].CGColor;
        button.layer.borderWidth =1;
        button.layer.cornerRadius =3;
        [bar addSubview:button];
        self.inputAccessoryView = bar;
        [button addTarget:selfaction:@selector(print)forControlEvents:UIControlEventTouchUpInside];
    }
    ``
    

    相关文章

      网友评论

          本文标题:iOS中实现键盘右上角完成按钮

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