Mac Cocoa |
Author |
Message |
XNote Kapetan
Joined: 16 Jun 2006 Posts: 532
|
Posted: Tue Sep 30, 2008 5:01 pm Post subject: Text & Strings |
|
|
SO - How to display test using Quartz on the iPhone?
"I've been trying to display text using a Quartz context, but no matter what
I've tried I simply haven't had luck getting the text to display (I'm able to
display all sorts of other Quartz objects though)." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Tue Oct 07, 2008 7:45 pm Post subject: |
|
|
SO - How to do string conversions in objective c?
"To really convert from a string to a number properly, you need to use an
instance of NSNumberFormatter configured for the locale from which you're
reading the string." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Tue Oct 14, 2008 5:02 pm Post subject: |
|
|
MF - Converting String To Data Without Encoding?
"If you were doing the conversion yourself anyways, you should probably
be using NSUTF8Encoding rather than NSUnicodeEncoding. Otherwise the
XML parser will choke as you see, since the text is 16-bit unicode, but the
XML says it is UTF-8." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Wed Jan 21, 2009 11:02 pm Post subject: |
|
|
daringfireball.net - Fonts From Mac OS X Included With iPhone
* Full font family included
* Partial font family included
* Not included, but name is special-cased
* Not included |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Wed Mar 04, 2009 1:44 am Post subject: |
|
|
cocoadev.com - UsingCustomFontsInYourCocoaApplications
(Cocoa, Carbon, whatever...)
"ATSFontActivateFromFileSpecification? is deprecated in Leopard. Here's
another version that uses ATSFontActivateFromFileReference? and expects
fonts in subdir (Resources/fonts). Note: be sure to check "Preserve HFS
Data" in your build settings if you are copying font suitcases to your resource
directory." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Wed Apr 22, 2009 9:31 pm Post subject: |
|
|
degutis.org - Finding all URLs in a string
"If you’ve ever wanted to find all the URLs in any NSAttributedString or NSStr-
ing, then this post is for you! It’s quite simple, actually, just a few lines of co-
de. So let’s take a look..." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat May 30, 2009 3:40 pm Post subject: |
|
|
MF - Cursor placement in UITextField
"I've got a UITextField on my interface that, ..."
"Method scrollRangeToVisible: is for class UITextView in iPhone SDK. Has
anyone solved this issue? " |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Jun 04, 2009 1:42 am Post subject: |
|
|
SO - How to parse strings in Objective C
"Can someone help me to extract int timestamp value from this string
"\/Date(1242597600000)\/" in Objective C"[/b] |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Tue Jun 09, 2009 11:34 pm Post subject: |
|
|
SO - How to word wrap text?
"Realized that I'm really looking for a word-wrap algorithm. For example, I
want the text to wrap at 80 characters; where do I place line breaks so that
words are not split over two lines?" |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Jun 15, 2009 12:05 am Post subject: |
|
|
macresearch.org - Parsing CSV Data
"As you can see, parsing CSV data can be very easy, but it is not always the
case. When you have to deal with general CSV data, things can get quite
complicated, because you have to take account of the possibility that strings
contain quotations, and can even extend over multiple lines." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Jun 15, 2009 1:03 am Post subject: |
|
|
adc - String Programming Guide for Cocoa
"Strings Programming Guide for Cocoa describes how to create, search, con-
catenate, and draw strings. It also describes character sets, which let you se-
arch a string for characters in a group, and scanners, which convert numb-
ers to strings and vice versa." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Jun 15, 2009 1:18 am Post subject: |
|
|
adc - rangeOfCharacterFromSet:options:range:
Finds and returns the range in the receiver of the first character from a gi-
ven character set found in a given range with given options.
- (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)aSet options:(NSStringCompareOptions)mask range:(NSRange)aRange
aSet - A character set. This value must not be nil.
mask - A mask specifying search options. The following options may be
specified by combining them with the C bitwise OR operator: NSCaseIn-
sensitiveSearch, NSLiteralSearch, NSBackwardsSearch.
aRange - The range in which to search. aRange must not exceed the bo-
unds of the receiver. |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Jun 15, 2009 1:22 am Post subject: |
|
|
adc - rangeOfString:options:range:
Finds and returns the range of the first occurrence of a given string, wi-
thin the given range of the receiver, subject to given options.
- (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask range:(NSRange)aRange
aString - The string for which to search. This value must not be nil.
mask - A mask specifying search options. The following options may be
specified by combining them with the C bitwise OR operator: NSCaseIn-
sensitiveSearch, NSLiteralSearch, NSBackwardsSearch, and NSAnchor-
edSearch. See String Programming Guide for Cocoa for details on these
options.
aRange - The range within the receiver for which to search for aString. |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Wed Jul 29, 2009 1:43 am Post subject: |
|
|
SO - How to make first letter of NSString Capital in iPhone dev
"You have to do it by hand. This is one of those things that has been built
into categories so often by so many people that Apple probably doesn't dare
add it as an actual method since it would generate category collisions." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Aug 08, 2009 10:46 pm Post subject: |
|
|
SO - Parsing HTML on the iPhone
"Can anyone recommend a C or Objective-C library for HTML parsing? It
needs to handle messy HTML code that won't quite validate."
html parsing with libxml
"Using libxml wont be a problem, assuming all of your documents are valid
XHTML, which is a subset of XML. If your documents are HTML (which inclu-
des "bad" things like the <br> tag) then libxml will probably fail to validate
and die because of the lack of closing tags (the same also goes for people
who don't close <p>)." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sun Aug 16, 2009 8:09 pm Post subject: |
|
|
so - iPhone string manipulation
"I need to remove the HTML tag, is there a way I can say remove everything
between ???"
EDIT:
so - Remove HTML Tags from an NSString on the iPhone
Code: | -(NSString *) stringByStrippingHTML {
NSRange r;
NSString *s = [[self copy] autorelease];
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
s = [s stringByReplacingCharactersInRange:r withString:@""];
return s; } |
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Mon Aug 24, 2009 5:44 pm Post subject: |
|
|
SO - Finding a string in a string
"Here we look for @"co_2", failing if it's not found, then use an NSScanner to
grab everything from just after that string to the next occurrence of @"end".
Note that if 'end' is missing this code will silently grab the rest of the string." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Sep 12, 2009 12:48 am Post subject: |
|
|
iphonedevsdk.com - Need help with getting data from the web
"Now, it works fine when it encounters Latin characters but when there are
Cyrilic or Chinese characters for example it won't recognize and display jibe-
rish.... What can be done?" |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Sep 14, 2009 10:24 pm Post subject: |
|
|
MF - NSData or NSString for CSV content?
"Should I just be using NSString's stringWithContentsOfFile and iterate over
the string to figure out the comma delimited data? .. I was looking at NSData
and I wasn't really clear how I iterate over the data in the NSData object. I
guess "byte" gets me the head pointer, and I increment the pointer to iterate
the length?" |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Oct 03, 2009 12:29 am Post subject: |
|
|
MF - NSRange Location For StringComparison
(UISearchDisplayerController)
"The contacts app also does an anchored search. So if you type S into the
search box you get all contacts that have S as the first letter of the first or
last name but you don't get every contact that has an S anywhere in the
name. That's what the range does in the example." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sun Oct 18, 2009 9:08 pm Post subject: |
|
|
MF - NSXMLParser and Windows encoding.. How?
"I have an application and I want to make it read greek characters based
on NSWindowsCP1253StringEncoding . NSXMLParser refuses to parse string
created with this encoding, but I need that encoding, since my application
loads data from these pages." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Nov 12, 2009 11:51 pm Post subject: |
|
|
SO - Simple Way to Strip Tags In Obj-C
"The problem is simple enough, find the first '>' and extract everything from
there until the first '<' as an NSString. That's all I need to do." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Nov 16, 2009 9:20 pm Post subject: |
|
|
MF - Drawing text in a custom view
"I am trying to figure out how to draw text in a custom view. I can use the
function CGContextShowTextAtPoint to draw the text, but how do I get in-
formation about the text extent so I can center or right justify the string?" |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Mon Feb 15, 2010 7:52 pm Post subject: |
|
|
so - How to count words within a text string?
"This is not the most efficient way to count words. Specially not memory
wise since it will split the whole string into a temporary array that will then
be discarded. It is much better to simply look at runs of whitespace and
punctiation in the text. This can't be done in one line but it will be much
faster and will not use at least double the memory of the text." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Apr 19, 2010 9:01 pm Post subject: |
|
|
SO - How to get the size of a NSString
"Trying to see if the string width of a string to see if it is bigger than a given
width of screen, case in which I have to "crop" it and append it with "...",
getting the usual behavior of a UILabel. string.length won't do the trick since
AAAAAAAA and iiiiii have the same length but different sizes (for example)." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Fri Apr 23, 2010 11:17 pm Post subject: |
|
|
SO - Is there something faster than -drawInRect...?
"To check and see if your string can be represented using the Mac Roman
character set, use something like the following:
if ([text canBeConvertedToEncoding:NSMacOSRomanStringEncoding])..." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon May 03, 2010 9:22 pm Post subject: |
|
|
SO - iPad Custom Font
"UIAppFonts (Array - iPhone OS) specifies any application-provided fonts
that should be made available through the normal mechanisms. Each item
in the array is a string containing the name of a font file (including filename
extension) that is located in the application’s bundle." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Mon Aug 16, 2010 9:29 pm Post subject: |
|
|
MF - Searching An HTML NSString
"Now, I am trying to search the html variable ... In this example, I am trying
to copy everything from <div class="FP_Up_Item2"> to </div> into it's own
variable." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sun Feb 13, 2011 4:21 pm Post subject: |
|
|
so - What is the “stringWithContentsOfURL” replacement ...?
"... the stringWithContentsOfURL command that is now deprecated as of
iPhone OS 3.0.
...
It has been replaced with stringWithContentsOfURL:encoding:error: or
stringWithContentsOfURL:usedEncoding:error:." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sun Mar 27, 2011 2:21 am Post subject: |
|
|
Jeff - Attributed Strings in iOS
"Ten months ago when the original iPad shipped, Apple released iOS 3.2,
and for the first time, iOS developers had access to NSAttributedString
and NSMutableAttributedString, objects designed to hold strings along
with font, paragraph, and style information. We no longer had to resort
to using heavy UIWebViews or complex Core Graphics calls to draw sty-
led text." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Fri Apr 01, 2011 10:03 pm Post subject: |
|
|
ADC - Reading data with an unknown encoding
"If you are forced to guess the encoding (and note that in the absence of
explicit information, it is a guess): Try stringWithContentsOfFile:usedEn-
coding:error: or initWithContentsOfFile:usedEncoding:error: (or the URL-
based equivalents).
..." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Oct 13, 2011 10:39 pm Post subject: |
|
|
beefyapps.com - Custom Fonts in iOS 4
"Up till now there hasn’t been an easy way to add custom fonts to your
iPhone applications. As of iOS 4 it has become very easy to do. Here is
what you need to do in order to add custom fonts..."
so - Can I embed a custom font in an iPhone application?
"Unfortunately, IB doesn't allow to initialize labels with custom fonts. See
this question to solve this problem. My favorite solution is to use custom
UILabel subclass..." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sun Apr 06, 2014 8:21 pm Post subject: |
|
|
github.com - jmenter / JAMValidatingTextField
"JAMValidatingTextField adds validation facilities to UITextField in iOS,
solving the problem of how to visually indicate that a text field's contents
are valid to the user.
It extends the basic UITextField to have three different validation states;
valid, invalid, and indeterminate. Validation is applied by either setting a
built-in validation type (email, URL, phone, or zip code) or by assigning a
validation block, an NSRegularExpression, or good old delegate." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Thu Dec 07, 2017 1:03 am Post subject: |
|
|
https://github.com/google/unigem-objective-c
This repository contains Unicode Gems, a Mac app, an iOS app, and an iOS keyboard that makes it easy for you to use interesting typefaces in contexts that don't allow fonted text.
As an iOS app, you get an iPhone UI, an iPad UI, and iPad split view support. |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon May 13, 2019 3:56 pm Post subject: |
|
|
so - Can I select a specific block of text in a UITextField?
Code: | // Get current selected range , this example assumes is an insertion point or empty selection
UITextRange *selectedRange = [textField selectedTextRange];
// Calculate the new position, - for left and + for right
UITextPosition *newPosition = [textField positionFromPosition:selectedRange.start offset:-5];
// Construct a new range using the object that adopts the UITextInput, our textfield
UITextRange *newRange = [textField textRangeFromPosition:newPosition toPosition:selectedRange.start];
// Set new range
[textField setSelectedTextRange:newRange]; |
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sat Jun 15, 2019 11:26 pm Post subject: |
|
|
https://schiavo.me/2019/scanning-documents/
Scanning documents with Vision and VisionKit on iOS 13
In iOS 13, Apple's Vision framework also adds support for OCR (Optical Character Recognition), which allows you to detect and recognize text on scanned documents! |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sun Nov 17, 2019 8:40 pm Post subject: |
|
|
so - NSAttributedString with tabs
Code: | let text = "Name\t: Johny\nGender\t: Male\nAge\t: 25\nFavourites\t: Reading, writing"
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.tabStops = [NSTextTab(textAlignment: NSTextAlignment.Left, location: 150, options: [:])]
paragraphStyle.headIndent = 150
label.attributedText = NSAttributedString(string: text, attributes: [NSParagraphStyleAttributeName: paragraphStyle])
|
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sat Jan 21, 2023 7:14 pm Post subject: |
|
|
so - Search through NSString using Regular Expression
Code: | NSString *yourString = @"";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"(NS|UI)+(\\w+)"
options:NSRegularExpressionCaseInsensitive
error:&error];
[regex enumerateMatchesInString:yourString options:0 range:NSMakeRange(0, [yourString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
// your code to handle matches here
NSLog(@"Text Range %@", match.range);
NSLog(@"Text %@", [yourString substringWithRange:match.range]);
}];
|
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sun Jan 22, 2023 12:34 am Post subject: |
|
|
mateam.net - HTML Escape Characters
"In the table below you can find the complete list of the most useful HTML
escape characters. Let us know if you use something we didn't cover so we
can update our list." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Sat Sep 09, 2023 4:46 pm Post subject: |
|
|
burnignorance.com - Padding Custom Margins In NSTextField
"Suppose we need to add padding to a text field or in a Table row (which is
generally a NSTextField cell).
This is possible but there in no direct method for this in Cocoa.
The padding can be added by subclassing NSTextFieldCell and by doing
customization as explained." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
Posted: Mon May 27, 2024 6:44 pm Post subject: |
|
|
papereditor.app - Apple rich text
"Rich text is a common term used to describe the text that can be styled by
the user. In most cases, the flow is such that the user first selects a piece of
text and then presses a button to toggle the desired style -- make it bold,
highlighted, bigger, etc. Think TextEdit or Microsoft Word."
https://papereditor.app/internals
https://papereditor.app/dev |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3127 Location: Europe
|
|
Back to top |
|
|
|