Questions tagged [sizewithfont]
57 questions
146
votes
8 answers
Replacement for deprecated -sizeWithFont:constrainedToSize:lineBreakMode: in iOS 7?
In iOS 7, the method:
- (CGSize)sizeWithFont:(UIFont *)font
constrainedToSize:(CGSize)size
lineBreakMode:(NSLineBreakMode)lineBreakMode
and the method:
- (CGSize)sizeWithFont:(UIFont *)font
are deprecated. How can I replace
CGSize…
![](../../users/profiles/2135917.webp)
user_Dennis_Mostajo
- 2,389
- 4
- 24
- 36
22
votes
4 answers
Resize CATextLayer to fit text on iOS
All my research so far seems to indicate it is not possible to do this accurately. The only two options available to me at the outset were:
a) Using a Layout manager for the CATextLayer - not available on iOS as of 4.0
b) Use…
![](../../users/profiles/303179.webp)
Dev Kanchen
- 2,192
- 2
- 25
- 39
17
votes
5 answers
iOS 7 - UITextView size font to fit all text into view (no scroll)
I am trying to find a non-deprecated method to size the font of a textview down so that all text fits in the textview without requiring scrolling.
The method 'sizeWithFont' is deprecated and I want to ensure best practices, and XCode says to use…
![](../../users/profiles/708831.webp)
JimmyJammed
- 9,308
- 17
- 74
- 140
11
votes
2 answers
Get the NSString height
I have an NSString, and I want to know its height to create an appropriate UILabel.
Doing this
NSString *string = @"this is an example";
CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:10.0f]
forWidth:353.0
…
![](../../users/profiles/344530.webp)
JAA
- 1,024
- 3
- 20
- 34
11
votes
11 answers
Check if there is an emoji contained in a string
I am getting the text size of a string with this
textSize = [[tempDict valueForKeyPath:@"caption.text"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(280, CGFLOAT_MAX) lineBreakMode: NSLineBreakByWordWrapping];
The only…
![](../../users/profiles/1530141.webp)
david2391
- 320
- 1
- 6
- 18
9
votes
2 answers
UILineBreakMode Vs NSLineBreakMode
I see some UIStringDrawing methods have been updated to use NSLineBreakMode instead of UILineBreakMode in iOS 6.0:
E.g.
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode
How can I…
![](../../users/profiles/248168.webp)
mootymoots
- 4,485
- 8
- 42
- 74
8
votes
1 answer
sizewithattributes not returning correct size
I am tring to calculate the height of text labels in uitableview cells. After seeing that sizewithfont was deprecated with ios 7, I implemented sizewithattributes but the return values were way smaller than what it should be for the label to be of…
![](../../users/profiles/2489946.webp)
user2489946
- 271
- 3
- 12
7
votes
2 answers
Convert CGSize to CGFloat and use that to size a RoundRectButton
I'm trying to find the physical pixel size of a string of text. I then want to use this size to set the length of a roundRectButton. The method I'm using to get the length however returns a CGSize. How do I convert that to a CGFloat? Alternatively…
![](../../users/profiles/1104563.webp)
ElasticThoughts
- 3,208
- 6
- 41
- 55
7
votes
3 answers
NSString sizeWithFont:constrainedToSize: returning incorrect height on retina displays
I think I have found an edge case for sizeWithFont:constrainedToSize: where, on a retina display, it will sometimes (it seems based on word wrapping) returns a height 1 line taller than is actually needed, and more importantly than is it actually…
![](../../users/profiles/351275.webp)
eric
- 381
- 2
- 12
4
votes
3 answers
UILabel rendering issue using boundingRectWithSize in iOS 7.0.3
I am trying to size a UILabel to fit the bounds of an NSString, but I'm seeing differing results in iOS 7.0.3 and iOS 7.1.1. As you can see below, iOS 7.0.3 doesn't seem to draw the text correctly.
Example 1: The text is drawn toward the bottom of…
![](../../users/profiles/444532.webp)
Ngoan Nguyen
- 617
- 1
- 9
- 19
3
votes
3 answers
-[NSString sizeWithFont:] returns different results in release and debug builds
I've used this code to resize a UILabel's frame height to fit dynamic text several times with success:
(...)
CGSize labelSize = [thelabel.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
All was well…
![](../../users/profiles/1028298.webp)
vfonseca
- 91
- 6
3
votes
2 answers
How to use NSString's sizeWithFont and drawInRect to workout how much of a string to draw
I'm drawing multiple 'pages' of imagery using a CGContext in the iOS. I've used sizeWithFont and drawInRect combinations extensively in my app. What I need to do is split a large chunk of text across multiple pages. I can size it and work out…
![](../../users/profiles/358980.webp)
Mike S
- 3,994
- 5
- 31
- 66
3
votes
3 answers
sizeWithFont in MultiThread Crash!
sizeWithFont crashed in multithread,this is the debug info:
1 0x00a0df8e in icu::RuleBasedBreakIterator::handleNext
2 0x00a0daff in icu::RuleBasedBreakIterator::next
3 0x00a0d174 in icu::RuleBasedBreakIterator::following
4 0x35879719 in…
![](../../users/profiles/425951.webp)
Db Xiong
- 97
- 1
- 9
3
votes
4 answers
Iphone sizewithfont doesn't work?
I have the following code:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *currentMessage = [FeedMessages objectAtIndex:indexPath.row];
NSLog(currentMessage);
UIFont *font = [UIFont…
![](../../users/profiles/392305.webp)
Trevor
- 51
- 1
- 4
3
votes
3 answers
IOS 7 sizeWithFont Deprecated
I cannot seem to replace the deprecated sizeWithFont with boundingRecWithSize correctly. I scoured through all the answers and stayed up all night trying to fix this.I really need help from someone way smarter than I. Here is the code I am trying to…
![](../../users/profiles/2175392.webp)
user2175392
- 53
- 1
- 1
- 5