|Apr 4, 2013, 02:43 PM||#1|
Drawn string changes in color but not in size
NSString *sNumber = [[NSString alloc] initWithFormat:@"%d", num]; // convert number into string NSMutableDictionary *attrib = [[NSMutableDictionary alloc] init]; // create a dictionary [attrib setObject:[NSColor colorWithDeviceRed:0 green:0.5 blue:0 alpha:1] forKey:NSForegroundColorAttributeName]; // change the color to dark green (works) [attrib setObject:@40 forKey:NSFontSizeAttribute]; // tries to change the size of the font to 40 (doesn't work) NSMutableAttributedString *masNumber = [[NSMutableAttributedString alloc] initWithString:sNumber attributes:attrib]; // create an attributed string with given string and attributes. NSSize omvang = [masNumber size]; // calculate the size NSLog(@"getal: %d, breedte: %f, hoogte: %f", num, omvang.width, omvang.height); // log the width, the height and the value (converted into string NSPoint startTekstPunt = NSMakePoint(tekstPunt.x - omvang.width / 2, tekstPunt.y - omvang.height / 2); // calculate were to draw [masNumber drawAtPoint:startTekstPunt]; // draw the string
What did I do wrong?
|Apr 4, 2013, 08:29 PM||#2|
The fundamental question you should ask yourself (then proceed to answer) is this:
Is NSFontSizeAttribute an attribute supported by NSAttributedString?
Some other questions you may wish to consider:
Are you following a tutorial or example? If so, what is the URL? Post it, so we know what you're following.
What reference docs have you read regarding NSAttributedString and its default supported attributes? If it's an online reference, what's the URL? If it's a book, what's the title, author, edition number, and page number? If it's Xcode's builtin docs, exactly which reference is it?
If you aren't doing any of those, and you haven't consulted a reference, what makes you think the code would work? I.e. explain your rationale.
Also see this:
Google search terms: NSAttributedString class reference
|Apr 5, 2013, 01:32 AM||#3|
Thanks for giving me a hint.
|Apr 5, 2013, 10:57 AM||#4|
It wasn't just a hint, it was a process. To summarize the process:
1. Find a tutorial.
2. If you can't find a tutorial, find a working sample or example.
3. If you can't find a working sample, find the reference docs.
4. When asking a question, tell everyone how you got there (i.e. give the URL of the tutorial, sample, and/or reference doc).
An important part of learning how to program is learning how to learn new things by discovery. That means having a repeatable process for finding tutorials, examples, and reference docs, and being able to confirm or refute your assumptions by referring to those docs.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|What size and color iPhone 6 are you getting?||Appl3FTW||iPhone||237||Sep 13, 2014 10:43 AM|
|iPhone 5 - Size and Color||stockcerts||iPhone||0||Sep 13, 2012 12:27 PM|
All times are GMT -5. The time now is 10:01 AM.