iOS How to set the line spacing of UILabel and adapt to the height of UILabel
Examples are as follows:
NSString *contentStr = @"I always thought that in the first place, there would be the original me, and there would be the original you."; UILabel *tempLabel = [[UILabel alloc] init]; //Set background color = [UIColor redColor]; //Set content = contentStr; //Set font color = [UIColor whiteColor]; //Set font size = [UIFont systemFontOfSize:15.0]; //Set whether the text is displayed in multiple lines = 0; = NSLineBreakByWordWrapping; //Set UILabel adaptive height according to text CGSize size = [tempLabel sizeThatFits:CGSizeMake(100, MAXFLOAT)]; //Set frame = CGRectMake(50, 100, 100, ); [ addSubview:tempLabel]; //Set the line spacing of label NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:8]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [contentStr length])]; [tempLabel setAttributedText:attributedString]; [tempLabel sizeToFit];
The above method of setting the line spacing and adaptive height of UILabel on iOS is all the content I share with you. I hope you can give you a reference and I hope you can support me more.
Related Articles
iOS imitation AirPods popup animation
This article mainly introduces the implementation of the iOS imitation AirPods pop-up animation in detail. The sample code in the article is introduced in detail and has certain reference value. Interested friends can refer to it.2019-12-12iOS uses CoreMotion to achieve the shake function
This article mainly introduces in detail to iOS using CoreMotion to implement the shake function, which has certain reference value. Interested friends can refer to it.2018-06-06Solution to moving the keyboard input screen upward in IOS development
In the IOS method, you often encounter the keyboard blocking the screen. You often block the button below. The following editor will share with you the solution to moving the keyboard input screen upward in IOS development. Interested friends can take a look.2016-10-10Detailed explanation of value capture and pointer capture of iOS block
Block is a feature of C language level and runtime. The following article mainly introduces relevant information about iOS block value capture and pointer capture. The article introduces the example code in detail. Friends who need it can refer to it.2022-02-02Preliminary Configuration Guide for SQLite in iOS Application Development
This article mainly introduces the preliminary configuration guide for SQLite in iOS application development. SQLite is an extremely lightweight embedded database, which is very suitable for beginner developers. Friends who need it can refer to it.2015-12-12OC - 9. Draw download progress bar based on Quartz2D (demo)
This article mainly introduces OC-9. Drawing the download progress bar (demo) based on Quartz2D. Friends who need it can refer to it.2015-11-11iOS password is reset after entering the background for 1 hour
This article mainly introduces the relevant information about resetting iOS password 1 hour after entering the background. Friends who need it can refer to it2017-08-08How to implement a drawing board using OpenGL ES in iOS
This article mainly introduces the method of using OpenGL ES to implement a drawing board in iOS. The article introduces the example code in detail, which has certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.2020-03-03iOS 16 CocoaAsyncSocket Crash Repair Detailed Explanation
This article mainly introduces the detailed explanation of iOS 16 CocoaAsyncSocket crash repair. Friends in need can refer to it for reference. I hope it can be helpful. I wish you more progress and get a promotion as soon as possible.2023-01-01iOS enables access to photo albums and network pictures
This article mainly introduces the access to photo albums and network pictures in iOS. The editor thinks it is quite good. Now I will share it with you and give you a reference. Let's take a look with the editor2017-04-04