-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetTextSize.m
executable file
·43 lines (36 loc) · 1.17 KB
/
GetTextSize.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// GetTextSize.m
// WeiBo_Project
//
// Created by 1007 on 13-11-28.
// Copyright (c) 2013年 Ibokan. All rights reserved.
//
#import "GetTextSize.h"
@implementation GetTextSize
- (CGSize)getTextSizeWithWidth:(NSString *)aText
andFont:(NSInteger)fontSize
andWidth:(float)textWidth
{
//列宽
CGFloat contentWidth = textWidth;
// 用何種字體進行顯示
UIFont *font = [UIFont systemFontOfSize:fontSize];
//该行要显示的内容
NSString *content = aText;
//计算出显示完内容需要的最小尺寸
CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(contentWidth, 1000)];
return size;
}
- (CGSize)getTextSizeWithHeight:(NSString *)aText andFont:(NSInteger)fontSize andHeitht:(float)textHeight
{
//列宽
CGFloat contentHeight = textHeight;
// 用何種字體進行顯示
UIFont *font = [UIFont systemFontOfSize:fontSize];
//该行要显示的内容
NSString *content = aText;
//计算出显示完内容需要的最小尺寸
CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(1000, contentHeight)];
return size;
}
@end