ios - When do adjustsFontSizeToFitWidth or boundingRectWithSize change the context.actualScaleFactor? -


when actualscalefactor of nsstringdrawingcontext change?

the documentation says:

"if specified custom value in minimumscalefactor property, when drawing complete, property contains actual scale factor value used draw string."

my code:

mybutton.titlelabel!.font = uifont(name: "americantypewriter-bold", size: 40) mybutton.titlelabel?.adjustsfontsizetofitwidth = true mybutton.settitle("\(textstring)", forstate: .normal)  let attributes = [nsfontattributename : mybutton.titlelabel!.font] let attributedstring = nsmutableattributedstring(string:textstring, attributes:attributes)  let context = nsstringdrawingcontext() context.minimumscalefactor = mybutton.titlelabel!.minimumscalefactor  print("context: \(context.actualscalefactor)")  let resultingrect = attributedstring.boundingrectwithsize(mybutton.titlelabel!.bounds.size, options: .useslinefragmentorigin, context: context)  print("actual context after drawing: \(context.actualscalefactor)")  //want font size after adjustsfontsizetofitwidth has done magic:       //let actualfontsize = mybutton.titlelabel!.font.pointsize * context.actualscalefactor 

console log both text fits without being shrunk , longer text adjusted fit label's width both same:

context: 0.0 actual context after drawing: 1.0 

any idea step missing real scalefactor context after text has been sized fit label?

do in viewdidappear... worked me


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -