繁体   English   中英

UITextfield在编辑时不显示内容

[英]UITextfield don't show the content when editing

在此输入图像描述

嗨,我遇到了问题。 我自定义了像pic中第二个文本字段的文本字段,覆盖了该功能

-(void)drawRect:(CGRect)rect {

    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(self.h / 2, self.h / 2)];
    path.lineWidth = 0.5;
    [[UIColor lightGrayColor] setStroke];
    [path stroke];

}

-(CGRect)textRectForBounds:(CGRect)bounds {

    return CGRectMake(self.h / 2, self.h, self.w - self.h, self.h); 
}

当我在自定义文本字段中编辑时,内容未显示在其中,并且我结束编辑它,内容显示。 第一个文本字段是工作正常的系统样式。 希望有人能帮助我解决问题,非常感谢。

- (CGRect)textRectForBounds:(CGRect)bounds {
  return CGRectOffset(bounds, 0, 0);
}

- (CGRect)placeholderRectForBounds:(CGRect)bounds {
  return [self textRectForBounds:bounds];
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
  return [self textRectForBounds:bounds];
}

使用常量而不是零来设置代码中的自定义偏移量

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM