Say I have a UITextField
that is sized at 90% of the width of it's superview and it's text alignment is centered. So it looks roughly looks like this:
[ |------Hello123------| ] frame size example: 0,0,310,60
|frame?| this is the frame I"m looking for
The view that is holding the textField
contains many other objects like imageViews
and other text fields. I have a method that unions all the frames of the subviews to find the smallest frame that everything fits inside of.
My issue is that each textField
is always the same width regardless of the amount of content that was typed in. So the smallest frame is usually as wide as the label frame, even though the text does not fill the frame of the label. If there is only a few characters entered, then its frame should be very small for example.
I'd like a way to determine the rect where the text actually starts and stops, so I can use that as a frame value when trying to determine the smallest frame that will hold everything. Say the frame of the textField
was 0,0,310,60. The area where the text inside is might be something like 30,0,50,60 for example.
I have tried textRectForBounds
and editingRectForBounds
methods on UITextField
but they are returning basically the entire frame of the textfield. Probably I'm doing something wrong. Any help or snippets would be appreciated.
Thanks in advance for any help in determining the frame size around the text.