#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 300, 300)];
label.backgroundColor = [UIColor yellowColor];
//设置文本
label.text = @"Hello Linux Hello Linux Hello Linux Hello Linux Hello Linux ";
label.shadowColor = [UIColor redColor];
label.shadowOffset = CGSizeMake(5, -5);
[self.view addSubview:label];
label.lineBreakMode = NSLineBreakByCharWrapping;
label.numberOfLines = 0;
CGSize textSize = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(300,10000) lineBreakMode:NSLineBreakByCharWrapping];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, label.frame.size.width, textSize.height);
label.backgroundColor = [UIColor redColor];
//字体库
NSArray *names = [UIFont familyNames];
for (NSString * name in names ) {
NSLog(@"%@",name);
}
label.font = [UIFont fontWithName:@"Didot" size:15];
NSLog(@"%f,%f",textSize.width,textSize.height);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
计算字符串长度
最新推荐文章于 2021-02-15 07:56:57 发布