ios - Word wrapping for a UILabel not created in IB? -


i trying create uilabel entirely in code, not ib.

i want x,y corner position , width fixed, height vary according how text being presented, , text wrap , centered. text populated elsewhere. (it won't more 2 lines long though)

i have got far, not sure how make height variable , text wrap:

instructlabel = uilabel(frame: cgrectmake(screenwidth/2-350, screenheight-screenheight*0.2, 700, 50)) // guess don't want 50 height here though? instructlabel.backgroundcolor = uicolor.blackcolor()  instructlabel.preferredmaxlayoutwidth = 700 // conflict above or override? instructlabel.linebreakmode = .bywordwrapping instructlabel.textalignment = nstextalignment.center  instructlabel.text = "" instructlabel.font = fontsmall instructlabel.textcolor = uicolor.whitecolor() self.addsubview(instructlabel) 

you should use cgrectgetmidx , cgrectgetmidy constants instead of calculating screenwidth , screenheight values.

instructlabel = uilabel(frame: cgrectmake(cgrectgetmidx(self.view.frame),cgrectgetmidy(self.view.frame),self.view.frame,self.view.frame)) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -