ios - UILabel byWordWrapping misbehaving -


here code uilabel...

    var maximumlabelsize: cgsize = (chosenspecies.identifyingcharacteristics![index] nsstring).sizewithattributes([nsfontattributename: uifont.systemfontofsize(16)])     var identifyingcharacteristicsinformation = uilabel(frame: (cgrectmake(leftmargin, spacingvalue, maximumlabelsize.width, maximumlabelsize.height)))      identifyingcharacteristicsinformation.font = uifont(name: "helveticaneue-light", size: informationtextsize)     identifyingcharacteristicsinformation.textalignment = nstextalignment.left     identifyingcharacteristicsinformation.text = chosenspecies.identifyingcharacteristics![index]     identifyingcharacteristicsinformation.text = identifyingcharacteristicsinformation.text!.capitalizedstring     identifyingcharacteristicsinformation.textcolor=uicolor(red:0.0, green:0.0, blue:0.0, alpha:1)     identifyingcharacteristicsinformation.numberoflines = 0     identifyingcharacteristicsinformation.linebreakmode = nslinebreakmode.bywordwrapping     identifyingcharacteristicsinformation.preferredmaxlayoutwidth = picturecontainer.frame.width                       scrollview.addsubview(identifyingcharacteristicsinformation)     spacingvalue += identifyingcharacteristicsinformation.frame.height     scrollview.contentsize.height += identifyingcharacteristicsinformation.frame.height 

here happens. each 1 of these 'characteristics' printed using code above in loop. can see, characteristics long run right off screen.

http://imgur.com/hbine5n

i have been scouring web reasons why may happening several hours , have been coming dry. have leads why occurring? having difficulties working word wrap understanding not throughout. able apply in other places within code implementing these 2 lines.

label.numberoflines = 0 label.linebreakmode = nslinebreakmode.bywordwrapping 

here attempted implementation of eric qian's suggestion. working through applying it.

var maxsize: cgsize = cgsize(width: 320, height: 100) var maximumlabelsize: cgrect = (chosenspecies.identifyingcharacteristics![index] nsstring).boundingrectwithsize(maxsize, options: nsstringdrawingoptions.useslinefragmentorigin, attributes: [nsfontattributename: uifont.systemfontofsize(16)], context: nil) 

check width of label. believe on screen bounds. need use

cgsize maxsize = cgsizemake(320.0, 1000.0); cgsize maximumlabelsize = [string boundingrectwithsize:maxsize                      options:nsstringdrawinguseslinefragmentorigin                   attributes:@{nsfontattributename: uifont.systemfontofsize(16)}                       context:nil]; 

instead of sizewithattributes correct size of string. since sizewithattributes renders whole string in single line.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -