swift - Rotating UITextView programmatically -
there weird problem, if create uitextview
, rotate right after creating it, lines or characters not visible! try this:
mytextview.font = uifont.boldsystemfontofsize(20) mytextview.text = "hello world wht hell\nhello mrs lorem ipum!" let maxsize = cgsizemake(700, 700) let frame = mytextview.sizethatfits(maxsize) mytextview.frame = cgrectmake(200, 200, frame.width, frame.height) view.addsubview(mytextview) mytextview.transform = cgaffinetransformmakerotation(cgfloat(m_pi_2))
result:
you see? of lost! if remove mytextview.transform = cgaffinetransformmakerotation(cgfloat(m_pi_2))
, run through button it's fine:
you can view code on git: https://github.com/maysamsh/rotatetextview
as workaround, try set uitextview
in simple uiview
, , rotate uiview
.
it should because way, uitextview
should react it's not rotated (so can set inset constraints superview)
then have care form of superview.
other solution
mytextview.font = uifont.boldsystemfontofsize(20) mytextview.text = "hello world wht hell\nhello mrs lorem ipum!" let maxsize = cgsizemake(700, 700) let frame = mytextview.sizethatfits(maxsize) mytextview.frame = cgrectmake(200, 200, frame.width, frame.height) view.addsubview(mytextview) let delaytime = dispatch_time(dispatch_time_now, int64(0.1 * double(nsec_per_sec))) dispatch_after(delaytime, dispatch_get_main_queue()) { mytextview.transform = cgaffinetransformmakerotation(cgfloat(m_pi_2)) }
a bit dirty, should work, user might see small clipping, shouldn't see it.
Comments
Post a Comment