Matt Winters
Matt Winters

Reputation: 1109

UITextField Vertical Alignment

Is there a way to vertically align text in a UITextField half-way between UIControlContentVerticalAlignmentCenter and UIControlContentVerticalAlignmentBottom or do I have to go with one of those?

Upvotes: 44

Views: 16636

Answers (1)

Kenn Cal
Kenn Cal

Reputation: 3679

You should subclass a UITextField, and override the following methods:

- (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);
}

Upvotes: 4

Related Questions