How to rebuild EMail-App text style?
I want to have a text-send view like the send-email view from the email app by apple. (the default iPhone emailapp).
I tried a UIScrollView with 2 TextFields and 1 TextView, but it looks not good, the scrollview has no function and the view does not scroll when I enter a text in the TextView (the text is hiding in the third line when I type...
Here is a picture: http://s3.imgimg.de/uploads/Bildschirmfoto20110823u开发者_StackOverflow中文版m1156940f792556940f791456940f79png.png
It should look like this: http://a5.mzstatic.com/us/r1000/032/Purple/ea/4f/03/mzl.bxracfen.320x480-75.jpg
How to rebuild?
to scroll downside when you start writing the text inside UITextfield, use this :
[yourScrollView scrollRectToVisible:CGRectMake(yourTextfield.frame.origin.x,yourTextField.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
Also, when you edit your TextView (i.e in the textViewDidBeginEditing method), make its frame smaller so as to make it fully visible. Then, when you finish editing the text (i.e in the textViewDidEndEditing method) set the frame to whatever it was, originally.
EDIT:
//add this in .h file
NSInteger originalHeight;
//in .m file
- (void) textViewDidBeginEditing:(UITextView *)textView
{
[yourScrollView scrollRectToVisible:CGRectMake(yourTextView.frame.origin.x,yourTextView.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
//now set the frame
//you just need to change the height, rest can be kept whatever they are
//set the newHeight so as to make the textview visible
originalHeight = yourTextView.frame.size.height;
yourTextView.frame = CGRectMake(x,y,width,newHeight);
//rest of the code
}
Now when editing is completed, set the height to as it was before.
- (void) textViewDidEndEditing:(UITextView *)textView
{
yourTextView.frame = CGRectMake(x,y,width,originalHeight);
}
精彩评论