objective-c – UILabel归属文本和minimumScaleFactor
发布时间:2020-12-16 05:47:13 所属栏目:百科 来源:网络整理
导读:是否可以同时使用minimumScaleFactor和归因文本字符串? [myLabel setFrame:CGRectMake(6,200,25)]; NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"A very long string and its first 20 characters should be
是否可以同时使用minimumScaleFactor和归因文本字符串?
[myLabel setFrame:CGRectMake(6,200,25)]; NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"A very long string and its first 20 characters should be bold"]; [attStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17] range:NSMakeRange(0,20)]; myLabel.attributedText = attStr; [myLabel setAdjustsFontSizeToFitWidth:YES]; [myLabel setAdjustsLetterSpacingToFitWidth:YES]; [myLabel setMinimumScaleFactor:0.3]; 这似乎不起作用如果我设置myLabel.text,它会按预期缩放.我如何缩放工作正常? 解决方法
您可以拿起第一个20个角色的部分并获得宽度,然后以相同的方式拍摄其余部分的宽度:
CGSize maximumLabelSize = CGSizeMake(500.0,20.0);//write a really long width //this will turn the expected length of the labels.. CGSize expectedFirstLabelSize = [[[[NSMutableAttributedString alloc] initWithString:@"A very long string and its first 20 characters should be bold"] substringToIndex:21] sizeWithFont:[UIFont boldSystemFontOfSize:17] constrainedToSize:maximumLabelSize lineBreakMode:nil]; CGSize expectedLastLabelSize = [[[[NSMutableAttributedString alloc] initWithString:@"A very long string and its first 20 characters should be bold"] substringFromIndex:20] sizeWithFont:[UIFont normalSystemFontOfSize:15] constrainedToSize:maximumLabelSize lineBreakMode:nil]; 那么你会知道他们的长度的速度..例如第一部分是140像素,其余是260像素,你的标签区域是100像素,那么你可以创建两个不同的标签,35像素和65像素.然后可以对这两个标签使用setAdjustsFontSizeToFitWidth. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |