44

UITextField有没有办法在中间垂直对齐文本,UIControlContentVerticalAlignmentCenter或者UIControlContentVerticalAlignmentBottom我必须使用其中一个?

4

1 回答 1

4

您应该继承 UITextField,并覆盖以下方法:

- (CGRect) textRectForBounds: (CGRect) bounds
{
  CGRect origValue = [super textRectForBounds: bounds];

  /* Just a sample offset */
  return CGRectOffset(origValue, 0.0f, 4.0f);
}

- (CGRect) editingRectForBounds: (CGRect) bounds
{
  CGRect origValue = [super textRectForBounds: bounds];

  /* Just a sample offset */      
  return CGRectOffset(origValue, 0.0f, 4.0f);
}
于 2012-12-10T03:54:25.053 回答