Shadow inside text on NSTextField/NSTextFieldCel - objective-c

I've been trying for a day or two to try and get a shadow to draw inside the text of an NSTextField (and making the foreground color transparent, so all you see is a shadow inside the text). I've yet to achieve a desirable and practical result. The only success I had with this was transforming the text into an NSBezerPath, subtracting it from the frame of the NSTextFieldCell and clipping using the setClip method (addClip does not suffice in this case, it leaves the background painted). Unfortunately, converting the text to an NSBezerPath makes the edges of the text look jagged and overly straightened. Is there an efficient and decent way to achieve this using CoreGraphics masks and clipping because I am unable to achieve this.
A very similar effect of what I would be looking for is in the Xcode IDE, if you don't have a debug session open and go to the debugger navigator it says "No Debug Session" in a subclassed NSTextField that draws the text with a shadow inside it. That is pretty nearly what I am after. Any insight on where to start and how to do this would be great.
A paste bin my current code (working, but sub-optimal, & non-working): http://pastebin.com/4pTv8ZWm

Have you played around with the shadow property of NSTextField in IB? You should be able to get pretty close using a slightly offset shadow effect on the text with the right blend of alpha transparency.

Related

How to layout the UIlabel object according to design spec in iOS

I have some difficult time in creating iOS screen to match with visual design provided by design team.
The design team has provided the spacing info for each screen which shows how much space each text needs to be apart from other UI element on the screen. This is attached for your reference. You can see here that the two text labels "Activate Your Account" and "A Verification link...." are placed apart by 25px.
The same thing I am trying to achieve in the storyboard. I am attaching the storyboard screen snapshot for reference.
From this you can see that I cannot keep exactly 25px b/w the two text labels because for the following issue
The text font is custom font and I cannot load the same in storyboard. I have added the font file in the project, but when I try to open it in storyboard for UILabel, it doesn't list out. I am not sure why xcode doesn't show up. This makes me hard to resize the label's frame. If I try to decrease the empty space in the label (upper and lower part of the text), this will make label height less, but when I set the font programmatically, it doesn't fit in this small space.
When I try to increase the height of the label, the text inside the label starts displaying at the center leaving space at the top and bottom of the label frame.
So I want to know how to solve this problem. If anyone had this issues and sorted out, please let me know how to fix this.
Many Thanks
Your designers aren't speccing their designs correctly :) Show them how iOS renders text and have them spec their designs in the same way. This is what we do on the Facebook design team. I mocked up an example for you (each square is 4dp/8px).
http://i.stack.imgur.com/q4tZX.png

Pixate background-image no-repeat?

I am trying to put a background image into a text-field (it's just a search icon). And it is tiling the image in the text field. Is it possible to turn off the repeating of the image? i don't see anything like that, i'm seeing padding and position for background images but nothing to turn off the tiling of the image. is this not possible in pixate yet?
thanks!
You should be able to set background-size to the size of your text-field so it won't have anything to repeat.
I battled this same problem, and in the end, I found I got what I wanted by using multiple objects. Even if you get the search icon to work right, you're probably going to notice the UITextField doesn't pad the text away from the icon.
Anyway, here's how I ended up doing it so that I had full control over the style.
So you can put your search icon in the UIImageView and then define your text field's style (border, background color, etc.) with the UIView. The UITextField ends up being plain white/transparent, and positioned so that its text doesn't overrun the search icon.
I hope that helps.

Optimize Custom Drawables

I'm drawing some custom shapes behind a textview to make it appear it's a notepad. It draws a repeating bitmap across the top, as well as a white background under the text, and a secondary "note" page under the rest to add a little dimension and layering. See the screenshot:
Now, this is with setDrawingCacheEnabled(true) for the TextView this drawable is applied to. With this method call applied, the scrolling is VERY smooth, exactly what I want. Without it, the black background disappears, but the scrolling is very choppy. Any idea on how to cache this view so that scrolling is smooth without destroying my UI?
Seems this function only works with solid colors, as defined in the documentation which I should have read before posting. I find it hard to believe there's nothing that caches complex views and drawables to work as well as that function does, but, whatevs. Live 'n learn.

Tips on implementing a custom UITextView interface on the iPhone?

I am trying to implement a control to edit text that will display the text in multiple colors. None of the solutions I have attempted yet have been good enough.
UITextView cannot accomplish this. All of the text must be the same color.
Using CoreGraphics to draw the text does not allow the text to be selected.
Using a UIWebView, DIV and PRE tags cannot be set to contentEditable on Mobile Safari.
Currently playing with using an off-screen TEXTAREA and an on-screen DIV to show the rendered text. This works pretty well, except supporting all of these at the same time seems impossible: click-to-type, click-to-move-cursor, click-and-hold-select/copy/paste.
Anyone have any tips on this predicament?
I've been trying to find any preexisting library out there that will accomplish this in a good way, to no luck. I'm open to any ideas!
Well, just pulling an idea out of my... let's say hat.
Could you put a transparent UITextfield over a view that draws the text? If the background was clear and the text color was clear the user could not perceive it but it should still respond to all commands. As the user enters and edits text you could draw the results on the view underneath.
I think the selection would work without any modification at all. When the user selected the clear text, it should create the illusion of selecting the drawn text automatically.
Like this one? StyledText http://three20.info/gfx/overview/styledtext.png It's in Three20 .
Here is an idea. I have no idea if it would work.
If you are only using colors, and not styles, the a UIWebView with colored text might layout text in exactly the same way as a UITextView. You could put a UITextView with invisible ink (text and background fully transparent) over a UIWebView and mirror the contents with colors in the html. I assume you can do scrolling with javascript along with the colored layout.

IKImageView and scroll bars

I have an NSScrollView with an IKImageView inside to display images. This seems to work.
However, if I make the window smaller than the image, the scrollbars appear as they should, but the BOTTOM of the image is locked to the bottom of the window, instead of the top of the image being locked to the top of the window. In other words, I want the image to not move on the screen when I re-size the window from the bottom right.
I understand why this is, because in All of these classes, the origin is in the lower left, not the upper left. However, It's still behaving wrong. If you look at any other product (including Preview, which I assume is written with some of these libraries) the image/content/whatever, is locked to the top not the bottom.
How do I do this?
I've looked for methods in the NSScrollView and IKImageView. I've considered capturing the scroller events and manually moving the image down or up as appropriate, but I haven't seen a way to do this (Set the selector to a method I write in the controller?) and anyway, that seems very messy...
Is there an easy way to do this?
thanks.
Solution for future reference:
Make a subclass of IKImageView with only one over-ridden method:
-isFlipped()
{
return YES;
}
This subclass will also prove useful if I find that I need to re-implement the rotate:(id) method and the setImage:(NSImage) method which exist in the class (and in the case of rotate are USED IN THE DEMO supplied by Apple) but not documented, and therefore not officially supported...