sizewithfont

CTFrameGetVisibleStringRange equivalent for iOS programming?

时间秒杀一切 提交于 2020-01-06 04:34:11
问题 I need a method like CTFrameGetVisibleStringRange that can give me the text that will be rendered in a given size supplied with a line break mode (i.e. word wrap). For example I have a long line of text.. and I have a given rectangle to draw the text wrapped in it, but wherever the text gets trunecated, I continue rendering it in another area where it left off. So I need a method like: NSString * text = "The lazy fox jumped over the creek"; [text drawAtPoint:CGPointMake(0, 0) forWidth:20

How to use NSString's sizeWithFont and drawInRect to workout how much of a string to draw

为君一笑 提交于 2019-12-18 12:03:12
问题 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 whether or not it needs another page but how do I know where to chop it? Do I have to do an ugly loop to check word by word until I find a string length that perfectly fits the page and then chop the string at that point? Is there a smarter way? Any

Resize CATextLayer to fit text on iOS

倾然丶 夕夏残阳落幕 提交于 2019-12-18 11:51:07
问题 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 sizeWithFont:constrainedToSize:lineBreakMode: and adjust the frame of the CATextLayer according to the size returned here. Option (b), being the simplest approach, should work. After all, it works perfectly with UILabels. But when I applied the same frame calculation to

Resize CATextLayer to fit text on iOS

喜欢而已 提交于 2019-12-18 11:49:00
问题 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 sizeWithFont:constrainedToSize:lineBreakMode: and adjust the frame of the CATextLayer according to the size returned here. Option (b), being the simplest approach, should work. After all, it works perfectly with UILabels. But when I applied the same frame calculation to

sizewithfont always returns the same value no matter what string is used

大憨熊 提交于 2019-12-12 13:43:33
问题 I want to calculate the height of a tableviewcell according to its text. I'm using CGSize userInputSize = [userLabel sizeWithFont:[UIFont fontWithName:@"Arial" size:18.0f] forWidth:[tableView frame].size.width-10 lineBreakMode:NSLineBreakByWordWrapping] but somehow the return value is always 22 (size of the font). Strange thing is that when I'm using CGSize userInputSize = [userLabel sizeWithFont:[UIFont fontWithName:@"Arial" size:18.0f] constrainedToSize:[tableView frame].size lineBreakMode

sizeWithFont in MultiThread Crash!

我怕爱的太早我们不能终老 提交于 2019-12-10 10:06:47
问题 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 WebCore::nextBreakablePosition 5 0x3587842a in -[NSString(WebStringDrawing) _web_drawInRect:withFont:ellipsis:alignment:lineSpacing:includeEmoji:measureOnly:] 6 0x35877da3 in -[NSString(WebStringDrawing) _web_sizeInRect:withFont:ellipsis:lineSpacing:] 7

iOS 7 - UITextView size font to fit all text into view (no scroll)

对着背影说爱祢 提交于 2019-12-09 08:02:01
问题 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 'boundingRectWithSize' but not sure how to use this to size a font down so that all text fits. Any suggestions? And NO I can not use a UILabel instead. I need to have the text vertically aligned at the top and UILabel does not do this. This worked Pre

NSString font size specific to frame width

无人久伴 提交于 2019-12-07 11:46:58
问题 I am using drawRect for a text display, calling NSString . I am trying to implement using sizeWithFont to auto resizing font (shrinking) with default font size of 17 and using a loop to reduce the font size by 1 if it does not fit the size of width. Can anyone help me how to implement this? Example would be nice right now I just have the font size set to 17.0 [[self.string displayName] drawAtPoint:CGPointMake(xcoord, ycoord) withFont:[UIFont boldSystemFontOfSize:17.0]]; CGSize size = [[self

sizeWithFont in MultiThread Crash!

梦想与她 提交于 2019-12-06 03:42:25
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 WebCore::nextBreakablePosition 5 0x3587842a in -[NSString(WebStringDrawing) _web_drawInRect:withFont:ellipsis:alignment:lineSpacing:includeEmoji:measureOnly:] 6 0x35877da3 in -[NSString(WebStringDrawing) _web_sizeInRect:withFont:ellipsis:lineSpacing:] 7 0x3090d238 in -[NSString(UIStringDrawing) sizeWithFont:constrainedToSize:lineBreakMode:lineSpacing:] 8

UILineBreakMode Vs NSLineBreakMode

China☆狼群 提交于 2019-12-05 18:53:44
问题 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 check for this to ensure my iOS 5 users and below continue to use UILineBreakMode? 回答1: No checking is necessary. These are just enums and they map to the same values You can see there is no real difference here: UILineBreakMode vs NSLineBreakMode enum