Solve the problem of Uitextfield text offset when entering

Source: Internet
Author: User
Method 1
Textfield.clearbuttonmode = uitextfieldviewmodewhileediting;
Method 2
Inheritance Uitextfield override method
-(CGRect) Textrectforbounds: (cgrect) bounds 
{return
    cgrectinset (bounds, 2, 1);
}

-(CGRect) Editingrectforbounds: (cgrect) bounds 
{return
    cgrectinset (bounds, 2, 1);
}
Method 3
If the text size is not high, the display area is large enough, Uitextfield can be displayed normally.
//When Uitextfield cannot fully display Chinese characters, it becomes scrollable, the text is below the centerline, and when you click the Delete button, it looks downward.
//Using the Layoutsubviews method of the NSLog output Uitextfield, the Uitexteditor Contentoffset is shown to have an offset.
//So rewrite the Layoutsuviews method to reset the contentoffset.y of the uitexteditor after [Super Layoutsubview].
-(void) Layoutsubviews
{
    [super layoutsubviews];
    For (Uiscrollview *view in self.subviews) 
  {
        if ([View Iskindofclass:[uiscrollview class]])
     {
            Cgpoint offset = View.contentoffset;
            if (offset.y!= 0) 
           {
                offset.y = 0;
                View.contentoffset = offset;
            }
            break;
    }
}

Refer to the following three posts
Post 1–stackoverflow
Post 2–stackoverflow
Post 3–cocoachina

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.