label自适应和字体行间距字间距的设置

阻焊剂
label⾃适应和字体⾏间距字间距的设置
#import <Foundation/Foundation.h>
@interface LabelLayout : NSObject
/// label设置⾏间距参数1:内容参数2:label 参数3:⾏间距参数4:字间距参数5:字⼤⼩参数6:label的宽度
+(CGSize)AdaptiveLabelText:(NSString *)str andLabel:(UILabel *)label andLineSpac:(CGFloat )lineSoac andFontSpac:(NSNumber *)fontSpac andFontSize:(CGFloat )fontSize andWidth:(CGFloat )labelWidth;
/// 设置不同的字体⼤⼩参数1:开始位置参数2:结束位置参数3:设置的内容
+(NSAttributedString *)setDifferFontSzie2:(NSInteger )len1 andEndIndex:(NSInteger )len2 andString:(NSString *)str andFontSize:(float )size;
///设置button宽度⾃适应参数1:字体⼤⼩参数2:要显⽰的内容
+(CGFloat)buttonWidth:(CGFloat )fontSize andStr:(NSString *)str;
///设置label宽度⾃适应参数1:要显⽰的内容参数2:字体⼤⼩
上栗论坛
+(CGFloat)LabelWithStr:(NSString *)str andFont:(CGFloat )foutSize;
/// 设置不同的字体颜⾊参数1:开始位置参数2:结束位置参数3:设置的内容参数4:设置的颜⾊
+(NSAttributedString *)setDifferFontColor:(NSInteger )len1 andEndIndex:(NSInteger )len2 andString:(NSString *)str andColor:(UIColor *)color;
@end
//
//  LabelLayout.m
生态系统的稳定性//  VaolonUser
//
//  Created by sky on 16/4/9.
//  Copyright © 2016年 FanLang. All rights reserved.
//      关于label⼀些属性的公共⽅法
#import "LabelLayout.h"
#import "WidthHeight.pch"
@implementation LabelLayout
+(CGSize)AdaptiveLabelText:(NSString *)str andLabel:(UILabel *)label andLineSpac:(CGFloat )lineSoac andFontSpac:(NSNumber *)fontSpac andFontSize:(CGFloat )fontSize andWidth:(CGFloat )labelWidth{
label.numberOfLines=0;
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByWordWrapping;
paraStyle.alignment = NSTextAlignmentNatural;
paraStyle.lineSpacing = lineSoac;
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
NSDictionary *dic = @{NSFontAttributeName:[UIFont fontWithName:@"Arial" size:fontSize*mu], NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:fontSpac};
NSAttributedString *attributeStr;
if (str) {可比非受控价格法
attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
}else{
attributeStr = [[NSAttributedString alloc] initWithString:@"" attributes:dic];
福建江夏学院学报
}
label.attributedText = attributeStr;
return [str boundingRectWithSize:CGSizeMake(labelWidth, 9999999) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
}
+(void)setLabel:(UILabel *)label andFout:(CGFloat )foutSize andFoutColor:(UIColor *)color{
label.font=[UIFont fontWithName:@"Arial" size:foutSize*mu];
}
#pragma mark - 设置不同的字体⼤⼩
+(NSAttributedString *)setDifferFontSzie:(NSInteger )len1 andEndIndex:(NSInteger )len2 andString:(NSString *)str{
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
[text addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:14*mu] range:NSMakeRange(len1, len2)];
return text;
}
+(NSAttributedString *)setDifferFontSzie2:(NSInteger )len1 andEndIndex:(NSInteger )len2 andString:(NSString *)str andFontSize:(float
)size{
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];蒋春暄
[text addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:size*mu] range:NSMakeRange(len1, len2)];
return text;
}
#pragma mark - 设置不同的字体⼤⼩
+(NSAttributedString *)setDifferFontColor:(NSInteger )len1 andEndIndex:(NSInteger )len2 andString:(NSString *)str andColor:(UIColor *)color{
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
//    [text addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:14*mu] range:NSMakeRange(len1, len2)];
[text addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(len1, len2)];
return text;
}
#pragma mark - button⾃适应宽度
+(CGFloat)buttonWidth:(CGFloat )fontSize andStr:(NSString *)str{
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
CGFloat length = [str boundingRectWithSize:CGSizeMake(320, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width+5;
return length;
}
#pragma mark - label⾃适应宽度
+(CGFloat)LabelWithStr:(NSString *)str andFont:(CGFloat )foutSize{
CGRect rect = [str boundingRectWithSize:CGSizeMake(0, 10000.0) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:foutSize*mu]} context:nil];
return rect.size.width;
}
@end

本文发布于:2024-09-20 23:33:50,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/531030.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:参数   设置   位置   福建   可比
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议