Reputation: 1425
Why placeholder and text in UITextField have different indents? Placeholder's text seems to be shifted to right for a few pixels. How can i remove this indent?
Text Field was created in IB.
Upvotes: 0
Views: 1579
Reputation: 1425
I found out the reason of this behavior. It seems to be a bug in iOS 5.0. I created a new project then put UITextFields to screen and placeholders behave the same way. But when i changed my platform from 5.0 to 6.1, it worked! Placeholder is no long shifted from text. So i think it's a bug of iOS 5.0. Thanks all for answers!
Upvotes: 0
Reputation: 4731
You can override these 2 method to make the rect you want. Here they are :
- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)placeholderRectForBounds:(CGRect)bounds;
The link is here
As Apple said :
**placeholderRectForBounds:**
Returns the drawing rectangle for the text field’s placeholder text
- (CGRect)placeholderRectForBounds:(CGRect)bounds
Parameters
bounds
The bounding rectangle of the receiver.
Return Value
The computed drawing rectangle for the placeholder text.
Discussion
You should not call this method directly. If you want to customize the drawing rectangle for the placeholder text, you can override this method and return a different rectangle.
If the placeholder string is empty or nil, this method is not called.
**textRectForBounds:**
Returns the drawing rectangle for the text field’s text.
- (CGRect)textRectForBounds:(CGRect)bounds
Parameters
bounds
The bounding rectangle of the receiver.
Return Value
The computed drawing rectangle for the label’s text.
Discussion
You should not call this method directly. If you want to customize the drawing rectangle for the text, you can override this method and return a different rectangle.
The default implementation of this method returns a rectangle that is derived from the control’s original bounds, but which does not include the area occupied by the receiver’s border or overlay views.
Upvotes: 1
Reputation: 20021
It does not make any difference here!!
For moving it use
- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)placeholderRectForBounds:(CGRect)bounds;
Upvotes: 3