IOS development-UILabel automatic line feed and highly adaptive
This is mainly because someone on the Forum asked this question today. After solving the problem, Mark it by the way.
It is very simple, and the code is clearly written. Directly add the code.
UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (10,100,300, 50)]; label. text = @ "this afternoon, the city is cloudy to overcast with showers or thunderstorms. From this night to tomorrow there are cloudy with showers, and the rainfall can reach heavy rain. Northeast wind 5-6 level gust 7 level, gradually increased to 6-7 level gust 8 level. Today's highest temperature: around 26, the lowest temperature in the morning: around 22. Minimum temperature this morning: 21. Today's UV level: 2 levels, weak radiation intensity, appropriate protection. Tomorrow's Car Wash Index: 4 levels, the weather is rainy, not suitable for car wash. "; // Clear the background color label. backgroundColor = [UIColor clearColor]; // set the font color to a white label. textColor = [UIColor whiteColor]; // set the background color of the label to Black label. backgroundColor = [UIColor blackColor]; // The text Center shows the label. textAlignment = UITextAlignmentCenter; // you can specify a label for automatic line insertion. lineBreakMode = UILineBreakModeWordWrap; label. numberOfLines = 0; // adaptive height CGRect txtFrame = label. frame; label. frame = CGRectMake (10,100,300, txtFrame. size. height = [label. text boundingRectWithSize: CGSizeMake (txtFrame. size. width, CGFLOAT_MAX) options: NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes: [NSDictionary dictionaryWithObjectsAndKeys: label. font, NSFontAttributeName, nil] context: nil]. size. height); label. frame = CGRectMake (10,100,300, txtFrame. size. height); [self. view addSubview: label];
: