iphone - How can I center a UIView programmatically on top of an existing UIView using Autolayout? -


in case of successful foursquare checkin, iphone app shows adds view on top of view shown.

i want view centered on x , y , have definite width , height using autolayout, i'm not sure constraints add programmatically. know how in storyboard, i'm not sure type in code same view added later in response successful action in app.

i can't working , uiview has nib loads loadnibnamed:.

successview *successfulcheckinview = [[successview alloc] initwithframe:cgrectzero]; successfulcheckinview.placenamelabel.text = propervenue.name; successfulcheckinview.placeaddresslabel.text = propervenue.address; successfulcheckinview.delegate = self;  [self.ownervc.view addsubview:successfulcheckinview]; 

try this:

nslayoutconstraint *xcenterconstraint = [nslayoutconstraint constraintwithitem:view1 attribute:nslayoutattributecenterx relatedby:nslayoutrelationequal toitem:view2 attribute:nslayoutattributecenterx multiplier:1.0 constant:0]; [superview addconstraint:xcenterconstraint];  nslayoutconstraint *ycenterconstraint = [nslayoutconstraint constraintwithitem:view1 attribute:nslayoutattributecentery relatedby:nslayoutrelationequal toitem:view2 attribute:nslayoutattributecentery multiplier:1.0 constant:0]; [superview addconstraint:ycenterconstraint]; 

updated swift:

nslayoutconstraint(item: view1, attribute: .centerx, relatedby: .equal, toitem: view2, attribute: .centerx, multiplier: 1, constant: 0).isactive = true  nslayoutconstraint(item: view1, attribute: .centery, relatedby: .equal, toitem: view2, attribute: .centery, multiplier: 1, constant: 0).isactive = true 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -