iOS - Changing frame of a subview of a subclassed UIView (using storyboard with auto layout enabled) -


i building custom progress bar (subclass of uiview). add uiimageview uiview uses repeating images display progress. view added storyboard , can display fine, if try change frame displays whatever shown in storyboard file (i.e. if storyboard view has yellow background, code of uiview subclass changes green, if try change frame of uiimageview in code reflect current progress defaults yellow background)

i tried using these no luck:

[self updateconstraints]; [self layoutsubviews]; 

update

i know need setup constraint use autolayout. however, needs done programmatically creating subclassed uiview way. here code trying, know close can't quite work:

[self addconstraint:  [nslayoutconstraint constraintwithitem:self.progressview                               attribute:nslayoutattributewidth                               relatedby:nslayoutrelationlessthanorequal                                  toitem:nil                               attribute:nslayoutattributewidth                              multiplier:1                                constant:progresswidth]];  [uiview animatewithduration:3 animations:^{     [self.progressview layoutifneeded]; }]; 

when working autolayout 1 should never touch frame. whole point of using layout system frames inferred based on satisfiable constraints attached them.

without knowing more details way approach create nslayoutconstraint outlets storyboard view in question. example might have width constraint on progress view - creating nslayoutconstraint outlet width constraint allow update constant, in turn adjust frame.

example animation:

self.widthconstraint.constant = 300;  [uiview animatewithduration:0.4 animations:^{     [self.view layoutifneeded]; }]; 

update 5/15/2013

here example of creating constraint programatically using visual format constraints (easier use)

uiview *w_progressview = self.progressview nsarray *wc = [nslayoutconstraint constraintswithvisualformat:@"[w_progressview(200)]"                                                                               options:0                                                                               metrics:nil                                                                                 views:nsdictionaryofvariablebindings(w_progressview)]; 

(sorry formatting, long method...)

then add nsarray of constraints returned parent view:

[self addconstraints:wc]; 

the notation progressview(200) puts 200 point width on view progressview


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -