How can I check the characters on the screen in a UITextField?

I have a UITextField that shrinks and expands as a user UITextField text. If the width of the text field reaches the width of the screen, I want it to be aligned right so that the user can see the last input characters. In other circumstances, I want it to be left aligned.

Since the maximum width of the text field is not quite the same with the screen, I need to find a way to check if it has characters from the visible area.

Anyway to achieve this?

+7
ios objective-c uitextfield
source share
1 answer

You can try to check the width of the line that is in the field and compare it with the width of the field itself. It will look something like this:

 CGSize textSize = [self.field.text sizeWithAttributes:@{NSFontAttributeName:self.field.font}]; // If the text is larger than the field if (textSize.width > self.field.bounds.size.width) { // There is text that is not visible in the field. } 

This is pretty rude, but you have to shut you down.

+1
source share

All Articles