//gets the width of the string-(float) Widthforstring: (NSString *) value fontSize: (float) FontSize Andheight: (float) height{Uicolor*backgroundcolor=[Uicolor Blackcolor]; Uifont*font=[Uifont boldsystemfontofsize:fontsize]; CGRect SizeToFit=[Value Boundingrectwithsize:cgsizemake (Cgfloat_max, height) options:nsstringdrawinguseslinefragmentorigin attributes:@{ Nsforegroundcolorattributename:backgroundcolor, Nsfontattributename:font } Context:nil]; returnsizeToFit.size.width;}//get the height of a string-(float) Heightforstring: (NSString *) value fontSize: (float) FontSize Andwidth: (float) width{Uicolor*backgroundcolor=[Uicolor Blackcolor]; Uifont*font=[uifont boldsystemfontofsize:18.0]; CGRect SizeToFit=[Value boundingrectwithsize:cgsizemake (width, cgfloat_max) options:nsstringdrawinguseslinefragmentorigin attributes:@{Nsforegroundcolorattributename:backgroundcolor, Nsfontattributename:font} Context:nil]; returnsizeToFit.size.height;}
IOS string width and height adaptive