Text self-adaptive method of UILabel in ios
Text self-adaptive method using UILabel (ios7)
-(Void) initUserInterface {UILabel * label = [[UILabel alloc] init]; label. numberOfLines = 0; // you need to set the number of lines to an unlimited label. font = [UIFont systemFontOfSize: 15]; label. textAlignment = NSTextAlignmentCenter; label. text = @ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; CGSize size = [self sizeWithString: label. text font: label. font]; label. bounds = CGRectMake (0, 0, size. width, size. height); label. center = self. view. center; [self. view addSubview: label];} // defines a method to facilitate multiple label calls to increase code reusability-(CGSize) sizeWithString :( NSString *) string font :( UIFont *) font {CGRect rect = [string boundingRectWithSize: CGSizeMake (320,800 0) // limits the maximum width and height options: large | small // butes: @ {NSFontAttributeName: font} // The font Dictionary of the uploaded person. context: nil]; return rect. size ;}