简体   繁体   中英

UItextView text hidden

I am notes.app like app. I am setting UITextView's contentInset as

myTextView.contentInset = UIEdgeInsetsMake(0, 25, 0, -25);
myTextView.contentSize = CGSizeMake(295, myTextView.contentSize.height);

but that does not seems to work as I expected. Two characters are hidden.

I get this 收到

but if I set

myTextView.contentInset = UIEdgeInsetsMake(0, 25, 0, 0);
myTextView.contentSize = CGSizeMake(295, myTextView.contentSize.height);

I get actual text as

需要

please help.

fibnochi you can use a different approach to do this. I have used this in one of my app and it is working fine

First of all you need to get the size of UItextView which will carry all the data, for this you need to use NSString class delegate function

NSString* str = @"Your Entire string will come here";

CGSize size = [str sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:CGSize(295, any large digit for maximum height say 10000) lineBreakMode:UILineBreakModeWordWrap];

textView.contentSize = size;

Will this solve your problem or not. Please let me know

Can you please try the below?

myTextView.contentInset = UIEdgeInsetsMake(0, 25, 0, 25);
myTextView.contentSize = CGSizeMake(295, myTextView.contentSize.height);

Apple's discussions here .

" Edge inset values are applied to a rectangle to shrink or expand the area represented by that rectangle. Typically, edge insets are used during view layout to modify the view's frame. Positive values cause the frame to be inset (or shrunk) by the specified amount. Negative values cause the frame to be outset (or expanded) by the specified amount. " You can do like UIEdgeInsetsMake(0,25,0,25 )

try this code :)

myTextView.contentInset = UIEdgeInsetsMake(0, 25, 0, -25);
myTextView.contentSize = CGSizeMake(270, myTextView.contentSize.height);

May this will help you out :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM