在使用UITextView的時候遇到一個bug,自動換行的時候會光標會不停的跳動,并且文字無法顯示完全,最后找到解決方法:
// ios7 bug fix
//?check?if?the?device?is?running?iOS?7.0?or?later
NSString?*reqSysVer?=?@"7.0";
NSString?*currSysVer?=?[[UIDevice?currentDevice]?systemVersion];
BOOL?osVersionSupported?=?([currSysVer?compare:reqSysVer? options:NSNumericSearch]?!=?NSOrderedAscending);
if?(osVersionSupported)?{
NSTextStorage*?textStorage?=?[[NSTextStorage?alloc]?init];
NSLayoutManager*?layoutManager?=?[NSLayoutManager?new];
[textStorage?addLayoutManager:layoutManager];
NSTextContainer?*textContainer?=?[[NSTextContainer?alloc]?initWithSize:self.view.bounds.size];
[layoutManager?addTextContainer:textContainer];
yourTextView?=?[[UITextView?alloc]?initWithFrame:someFrameForYourTextView
textContainer:textContainer];
//?if?using?ARC,?remove?these?3?lines
[textContainer?release];
[layoutManager?release];
[textStorage?release];
}
else
yourTextView?=?[[UITextView?alloc]?initWithFrame:someFrameForYourTextView];