nslayoutconstraint - Create Three Columns using Visual Formatting Language (Swift) -


i trying create view following layout using vfl (visual formatting language)

 ------------------------------------------------- | [leftview]      [centerview]       [rightview]| ------------------------------------------------- 

but showing this

 ------------------------------------------------- | [leftview]                         [rightview]| ------------------------------------------------- 

i think problem line

h:|-10-[cancel(70)]-[title]-[save(70)]-10-| 

here rest of code don't know doing wrong. here code :

    let headerview = uiview(frame: cgrectmake(0,0,mainframe.width, headerheight))     headerview.backgroundcolor = bg_color     self.addsubview(headerview)      let cancelbutton = uibutton(type: .custom)     cancelbutton.translatesautoresizingmaskintoconstraints = false     cancelbutton.settitle("cancel", forstate: .normal)     cancelbutton.addtarget(self, action: "cancelbuttonclick:", forcontrolevents: .touchupinside)     headerview.addsubview(cancelbutton)      let titlelabel = uilabel()     titlelabel.text = "bedroom"     titlelabel.textcolor = uicolor.whitecolor()     headerview.addsubview(titlelabel)      let savebutton = uibutton(type: .custom)     savebutton.titlelabel?.textalignment = nstextalignment.right     savebutton.translatesautoresizingmaskintoconstraints = false     savebutton.settitle("save", forstate: .normal)     savebutton.addtarget(self, action: "savebuttonclick:", forcontrolevents: .touchupinside)     headerview.addsubview(savebutton)      let views = ["title":titlelabel, "cancel":cancelbutton,"save":savebutton,"header":headerview]      headerview.addconstraints(         nslayoutconstraint.constraintswithvisualformat(             "v:|[save]|",             options:[.alignallcentery],             metrics:nil,             views:views)     )      headerview.addconstraints(         nslayoutconstraint.constraintswithvisualformat(             "v:|[cancel]|",             options:[.alignallcentery],             metrics:nil,             views:views)     )      headerview.addconstraints(         nslayoutconstraint.constraintswithvisualformat(             "v:|[title]|",             options:[.alignallcentery],             metrics:nil,             views:views)     )      headerview.addconstraints(         nslayoutconstraint.constraintswithvisualformat(             "h:|-10-[cancel(70)]-[title]-[save(70)]-10-|",             options:[.alignallcentery],             metrics:nil,             views:views)     ) 

your code looks fine. phenomenon describe, center view not visible. have several reasons.

  • it has no content.
  • you set hidden property somewhere.
  • you have set alpha property zero.
  • you overriding layout in layoutsubviews.
  • the text of label has same color background.

as many other reasons... anyway, it's not line of vfl.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -