ios - Size a UIView created from a xib? -
i'm creating uiview xib render uiimage.
the uiview has internal constraints work fine given big plenty frame size in ib. however, need size width particular content, , can't figure out how set width of uiview after loading xib.
[[nsbundle mainbundle] loadnibnamed:@"myview" owner:self options:nil][0];
to render view, this:
uigraphicsbeginimagecontextwithoptions(view.bounds.size, no, 0.0); [view.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();
no matter set bounds to, however, uiview same size initial size in ib. how can set size of uiview such cause internal constraints resize , render correctly?
try setting desired frame of view , calling layoutifneeded on it:
uiview *view = [[nsbundle mainbundle] loadnibnamed:@"myview" owner:self options:nil][0]; cgrect finalframe = cgrectmake(0, 0, 90, 90); view.frame = finalframe; [view layoutifneeded]; uigraphicsbeginimagecontextwithoptions(finalframe.size, no, 0.0); [view.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();
ios uiview autolayout xib
No comments:
Post a Comment