views:

177

answers:

2

I have this weird bug with UITextField, sometimes there's a line (actually more of a transparent strip) through it. Does anyone know how to get rid of it?

Here's the picture

alt text

A link to xib file: http://db.tt/7l2Bq42

A link to the code: http://db.tt/DW0mlqQ

Edit: The bug is now solved. I'm creating this view programmatically rather than with a xib file, and the bug seems to be gone. Thanks everyone for your help.

+1  A: 

It seems that you have used center property of UITextField. If you use nameInput1.center, sometimes it gives this type of error.

You can use this line instead of setting center property.

nameInput1.textAlignment = UITextAlignmentCenter;

If you still finding some problem then please let me know. I love to solve this problem.

Tech Guru
Sorry, but the bug is stil present. I've made some changes to the code and I am now setting the frame instead of the center. You had this bug too?
tadej5553
Hello, Why are you using center property of UITextField? Is there any need for that? Can you please provide me the complete example so that I can debug and solve the problem.
Tech Guru
I'm using it, because I have to set its position. I can't give you the code for the whole app, but I can give you the .h file as well (and than you can make an app out of it). There are some unknown classes, just delete them. And this problem appears only on devices running OS 3.
tadej5553
the .h file: http://db.tt/ngPIHbL. Tell me if you need anything else.
tadej5553
A: 

If you get rid of the centering, does your problem go away?

You can avoid using textAlignment altogether by subclassing the UITextField and overriding the drawTextInRect: method. To compute the rectangle, use this NSString method:

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;
William Jockusch
I'm not using textAlignment. Only "half" of the problem went away now that I'm not setting the center property - the line now doesn't appear when both textfields are on the screen. Take a look at the code, maybe you can solve it.
tadej5553