【问题标题】:textfield subclass highlighting text iphone文本字段子类突出显示文本 iphone
【发布时间】:2013-09-06 08:18:00
【问题描述】:

我将 UITextfield 子类化为允许背景图像、占位符文本颜色。它在 iPad 中按预期工作。但在 iPhone 上,它一直突出显示蓝色,看不到任何文字输入。截图可见here

子类代码如下:

- (CGRect) textRectForBounds:(CGRect)bounds {
return CGRectInset(bounds, 10, 10);
}

- (CGRect) editingRectForBounds:(CGRect)bounds {
return CGRectInset(bounds, 10, 10);
}

- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor colorWithRed:.533 green:.553 blue:.220 alpha:1.0] setFill];
[[self placeholder] drawInRect:rect withFont:self.font lineBreakMode:NSLineBreakByTruncatingTail alignment:NSTextAlignmentLeft];
}

它在 iPad 上完美运行。这在模拟器和设备上都有。 任何人都可以对此有所了解。

【问题讨论】:

    标签: ios uitextfield


    【解决方案1】:

    对于将来遇到此类问题的其他人: 结果发现 iphone 中文本字段的高度较小,因此从上述方法返回的 rect 不正确。只是减少了插入值,它就像一个魅力。

    【讨论】:

      猜你喜欢
      • 2011-06-26
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多