sizewithfont

UILineBreakMode Vs NSLineBreakMode

与世无争的帅哥 提交于 2019-12-04 02:45:55
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? 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 { NSLineBreakByWordWrapping = 0, NSLineBreakByCharWrapping, NSLineBreakByClipping,

Check if there is an emoji contained in a string

你说的曾经没有我的故事 提交于 2019-11-30 08:52:46
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 problem I have is that if the string only contains an emoji, my app crashes. Is there an easy way to check for emojis or do I have to create an array with all possible emojis and then check for them using that? error: -[NSNull sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x3aa88a60 if ([tempDict valueForKeyPath:

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

泄露秘密 提交于 2019-11-30 05:31:40
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 ideas? Thanks. The NSString additions to UIKit for drawing text, you can pre-determine the exact amount of

Resize CATextLayer to fit text on iOS

流过昼夜 提交于 2019-11-30 04:44:49
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 CATextLayer, the frame was always turning out to be a bit bigger than expected or needed. As it turns

Check if there is an emoji contained in a string

我只是一个虾纸丫 提交于 2019-11-29 12:36:21
问题 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 problem I have is that if the string only contains an emoji, my app crashes. Is there an easy way to check for emojis or do I have to create an array with all possible emojis and then check for them using that? error: -[NSNull sizeWithFont

IOS 7 sizeWithFont Deprecated

余生长醉 提交于 2019-11-28 09:19:26
问题 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 modify. Any help would be appreciated. CGSize sizeForText = [faqItem.answer sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(self.tblView.bounds.size.width - padding, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];

Get the NSString height

末鹿安然 提交于 2019-11-27 03:22:25
问题 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 lineBreakMode:UILineBreakModeWordWrap]; float height = size.height; height is now 13.0. If I use this string NSString *string = @"this is an example this is an example this is an example this is an example this is an example this is an example this is an example this is an

Replacement for deprecated -sizeWithFont:constrainedToSize:lineBreakMode: in iOS 7?

断了今生、忘了曾经 提交于 2019-11-26 11:39:18
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 size = [string sizeWithFont:font constrainedToSize:constrainSize lineBreakMode:NSLineBreakByWordWrapping]; and: CGSize size = [string sizeWithFont:font]; Xavier Maroñas You could try this: CGRect textRect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT} context:nil]; CGSize size = textRect.size;

Replacement for deprecated -sizeWithFont:constrainedToSize:lineBreakMode: in iOS 7?

流过昼夜 提交于 2019-11-26 02:29:09
问题 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 size = [string sizeWithFont:font constrainedToSize:constrainSize lineBreakMode:NSLineBreakByWordWrapping]; and: CGSize size = [string sizeWithFont:font]; 回答1: You could try this: CGRect textRect = [text boundingRectWithSize:size options