[Code Note] iOS-UILabel automatically adjusts the height based on the content. Note ios-uilabel
I ,.
Ii. Code.
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // adjust the height automatically according to the content NSString * str = @ "in 3000 BC, the number of the residents in the Indian River Basin was widely used, and the residents adopted the decimal place calculation method. "; UIFont * font = [UIFont systemFontOfSize: 13]; CGSize size = CGSizeMake (); CGRect labelRect = [str boundingRectWithSize: size options :( optional | optional) attributes: [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName] context: nil]; // UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (50,100, labelRect. size. width, labelRect. size. height)]; label. text = str; label. backgroundColor = [UIColor redColor]; label. font = [UIFont systemFontOfSize: 13]; label. numberOfLines = 0; [self. view addSubview: label];}