美文网首页
ios 字体 屏幕变化 间距设定

ios 字体 屏幕变化 间距设定

作者: 开始就会被黏住 | 来源:发表于2018-07-26 11:32 被阅读0次

1.font的size是个大小 可以乘以系数和一个因数

2.宽度固定 label.adjustsFontSizeToFitWidth = YES; 或者XIb勾选

3.强制竖间距

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];

    paragraphStyle.maximumLineHeight = lineH;

    paragraphStyle.minimumLineHeight = lineH;

    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

    [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];

    CGFloat baselineOffset = (lineH - _explainLabel.font.lineHeight) /4;

    [attributes setObject:@(baselineOffset)forKey:NSBaselineOffsetAttributeName];

UILabel*label = [[UILabelalloc]init];

    label.attributedText = [[NSAttributedString alloc] initWithString:_explainLabel.text attributes:attributes];

4.横间距  https://blog.csdn.net/minggeqingchun/article/details/77334147

* 获取富文本的高度

*

* @param string    文字

* @param lineSpace 行间距

* @param kern      字间距

* @param font      字体大小

* @param width    文本宽度

*

* @return size

*/

- (CGSize)getAttributionHeightWithString:(NSString*)string lineSpace:(CGFloat)lineSpace kern:(CGFloat)kern font:(UIFont*)font width:(CGFloat)width {

NSMutableParagraphStyle*paragraphStyle = [NSMutableParagraphStylenew];

    paragraphStyle.lineSpacing = lineSpace;

NSDictionary*attriDict = @{

NSParagraphStyleAttributeName:paragraphStyle,

NSKernAttributeName:@(kern),

NSFontAttributeName:font};

CGSizesize = [string boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeadingattributes:attriDict context:nil].size;

returnsize;

}

相关文章

网友评论

      本文标题:ios 字体 屏幕变化 间距设定

      本文链接:https://www.haomeiwen.com/subject/anovmftx.html