ios - swift Autolayout 3 button set horizontally width manage according to text -
i have set button in 1 child view max button 3 , minimum 0 try set horizontally button take equal width , try set left aligned , depend on button text width , , 1 more problem if 1 button missing mean if button array count 2 , 1 not show 1 , please give me solution here code
let button1 = uibutton() let button2 = uibutton() let button3 = uibutton() print(getchannelname) var = 0; < getchannelname.count; i++ { if(i == 0) { button1.translatesautoresizingmaskintoconstraints = false button1.backgroundcolor = uicolor.greencolor(); button1.tintcolor = uicolor.blackcolor() button1.titlelabel?.textcolor = uicolor.blackcolor() button1.settitle("#\(getchannelname[i])" , forstate: uicontrolstate.normal) button1.titlelabel!.font = uifont(name: "arial", size: 12) }else if (i == 1) { button2.translatesautoresizingmaskintoconstraints = false button2.backgroundcolor = uicolor.yellowcolor(); button2.tintcolor = uicolor.blackcolor() button2.titlelabel?.textcolor = uicolor.blackcolor() button2.settitle("#\(getchannelname[i])" , forstate: uicontrolstate.normal) button2.titlelabel!.font = uifont(name: "arial", size: 12) }else { button3.translatesautoresizingmaskintoconstraints = false button3.backgroundcolor = uicolor.greencolor(); button3.tintcolor = uicolor.blackcolor() button3.titlelabel?.textcolor = uicolor.blackcolor() button3.settitle("#\(getchannelname[i])" , forstate: uicontrolstate.normal) button3.titlelabel!.font = uifont(name: "arial", size: 12) } } cell.viewchannel!.addsubview(button1) cell.viewchannel!.addsubview(button2) cell.viewchannel!.addsubview(button3) cell.viewchannel!.layer.borderwidth = 2 let leftconstraint = nslayoutconstraint(item: button1, attribute: .bottom, relatedby: .equal, toitem: cell.viewchannel!, attribute: .bottom, multiplier: 1.0, constant: 0.0); cell.viewchannel!.addconstraint(leftconstraint); cell.viewchannel!.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-0-[b1]-0-[b2(==b1)]-0-[b3(==b1)]-0-|", options: nslayoutformatoptions.alignallbottom, metrics: nil, views: ["b1": button1, "b2": button2, "b3": button3]))
array of name
**one** ( channelsnamelonggergo, general ) **two** ( trndnl, jive, banter ) **three** ( channelsnamelonggergo, trending, local ) **four** ( scoobydoobyparampaa, channelsnamesarebigmerge, enternewchannelsjive )
please give me soultion.
if have understood question, can manage using uistackview , creating 3 uibuttons inside it.
here link : https://developer.apple.com/library/ios/documentation/uikit/reference/uistackview_class_reference/
Comments
Post a Comment