获得字符串的宽度和惊人,获取字符串的可观和宽窄

收获字符串的肥瘦和中度,获取字符串宽度

 

代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    //获取字符串的宽度
    NSLog(@"获得字符串的宽度:%f",[self widthForString:@"我爱你!我爱你!我爱你!我爱你!我爱你!我爱你!我爱你!我爱你!" fontSize:10.0 andHeight:10.0]);

    //获取字符串的高度
    NSLog(@"获得字符串的宽度:%f",[self heightForString:@"我爱你!我爱你!我爱你!我爱你!我爱你!我爱你!我爱你!我爱你!" fontSize:10.0 andWidth:10.0]);



}

#pragma -mark -functions

//获取字符串的宽度
-(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
{
    CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置
    return sizeToFit.width;
}
//获得字符串的高度
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
    CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置
    return sizeToFit.height;
}

 

输出:

2015-03-11 15:37:05.375 得到字符串的上涨的幅度[4774:193097]
赢得字符串的增加率:320.000000

2015-03-11 15:37:05.376 收获字符串的宽度[4774:193097]
得到字符串的幅度:381.760010

 

代码: –
(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup
after loading the view, typically from a n…

{

– (void)viewDidLoad {

CGSize sizeToFit = [value sizeWithFont:[UIFont
systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width,
CGFLOAT_MAX)
lineBreakMode:NSLineBreakByCharWrapping];//此处的换行类型(lineBreakMode)可依照本身的莫过于情况张开设置

//获取字符串的莫斯中国科学技术大学学

//获取字符串的大幅

returnsizeToFit.width;

方法2:

{

}

-(float) heightForString:(NSString *)value fontSize:(float)fontSize
andWidth:(float)width

CGSize sizeToFit = [value sizeWithFont:[UIFont
systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX,
height)
lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型(lineBreakMode)可依照自个儿的其实际意况形开展设置

state=
[[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(pate.frame)
+6,10, labelsize.size.width,14)];

-(float) widthForString:(NSString *)value fontSize:(float)fontSize
andHeight:(float)height

CGSize sizeToFit = [value sizeWithFont:[UIFont
systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX,
height)
lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型(lineBreakMode)可依据本人的骨子里情状开始展览安装

CGRectlabelsize
=[@”门店已接单,用户打消订单”boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-150,2000)options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeadingattributes:@{NSFontAttributeName:Font(14)}context:nil];

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图