Add Uitextview control bug in the navigation bar of iOS

Source: Internet
Author: User

Today, a strange problem is encountered, as follows:

In the rootviewcontroller of the navigation bar controller, a Uitextview control is added with the following code:

-(void) Viewdidload {

[Super viewdidload];

Self. title =@ "Test";

uitextview *textview = [[uitextviewalloc]init];

TextView. frame = CGRectMake(ten, +, +) ;

TextView. backgroundcolor = [uicolorgreencolor];

TextView. layer. Cornerradius =5;

TextView. layer. maskstobounds =YES;

TextView. Font =[uifontboldsystemfontofsize:];

[Self. View addsubview: TextView];

}


The results are as follows:


Then the problem arises, the cursor appears in the middle, it is clear that the height of the navigation bar and the cursor distance uitextview the top distance is the same

Make the following changes to the code to solve the problem:

-(void) Viewdidload {

[Super viewdidload];

Self. title =@ "Test";

//before adding uitextview , add a UIView

[self. View addsubview: [UIViewnew]];

uitextview *textview = [[uitextviewalloc]init];

TextView. frame = CGRectMake(ten, +, +) ;

TextView. backgroundcolor = [uicolorgreencolor];

TextView. layer. Cornerradius =5;

TextView. layer. maskstobounds =YES;

TextView. Font =[uifontboldsystemfontofsize:];

[Self. View addsubview: TextView];

}


The results are as follows:


This shows: Before adding the Uitextview control in the viewcontroller of the navigation bar, you need to add a uiview, otherwise the cursor will move down one (navigation bar + status bar) height.

I do not know why this is the reason, please advise us.


Add Uitextview control bug in the navigation bar of iOS

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.