Draw panel in Cocoa - objective-c

I have a NSBezierPath, in the shape of a menubar panel.
I'd like to make a header now.
Like this one for example.
But only like 30 pixels from the top.
I can't figure out how I should only get the top part of the NSBezierPath.
This is my first question.
How can I cut off a piece of the NSBezierPath, or how can I make a Union of the NSBezierPath.
Then I want to add a gradient like in the example.
The gradient is clear, but how can I add the glow at the top of it?
I have added a shadow in another app back then, but it seemed a little dirty.
So how can I make a shadow at the top of the NSBezierPath, like in the provided example.
Thanks!

I ended up using PaintCode, which did a pretty good job for me.
This is the result:

To get the 'light' edge at the top of the element you can just draw (i.e. :fill) the NSBezierPath with a vertical offset of e.g. -1 points with a brighter color. Then draw the shape (at y=+1 points) on top of that.
Not sure what you mean by making the header and cutting of bits..

Related

Having troubles fitting the UIImageView and Label into Scroll View

I want to fit the Image + Label into Scrollable View.
It looks like so My setup
So trouble here is that width of the picture and the label did not match the screen width.
I tried to change the UIImageView width from 400 to 300 or so, BUT those changes either wont take the effect(if above 300), OR those changes make label disappear (with width setted up on 300 or below). Observe.
Funny thing is - label actually appears when you see view hierarchy, even though it looks kinda distorted. But no label on the iOS screen for you, sir.
I also tried to set equal width and height from the superview, but this option just disabling scroll, making view strictly fit the screen (label appears to be cropped)
I want the label to be nice and scrollable, but I also want to see it on the screen. Too much to ask?
EDIT: I just tried removing Auto-layout and got the same as with auto-layout. (click "Observe" link to take a look again, exact same situation) Could somebody explain why?
This is quite a simple fix. For the image, you should use equal width & center horizontally; however, make sure you use a fixed width. For the image to look nice, play with the scale modes - I find Aspect Fit/Fill work best.
The label should also be equal width & centered horizontally. You may need to calculate the height of the label programmatically if the text isn't always going to be the same size.
So the answer to my particular question was - shortening the actual text that is passed to the label.
Apparently UIScrollView can't handle stuff with crazy abnormal heights (I was passing a huuuge text to it) So in my particular situation solution was - shorten the text. Now it works like a charm (even though I still need to play a little with constraints to get rid of the warnings and stuff)

Custom TabBarItem menu IOS 7

I'm trying to make an UITabBarController like this:
No matter the device width (whether it is rotated or not) the buttons should not be stretched and the leftover space should be on the right side.
My questions:
Is this possible with the UITabBarController?
For the whitelines inbetween the buttons I am planning to use an unclickable UITabBarItem with an image. Is this the best way to do this?
With this tutorial that I followed I am getting this result:
2 problems here ^, whilst my background.png is 320x49, the selected image (68x49) has padding. This should not happen, both pictures have the same height?
The second problem is that the button/image has trailing space, and I want it sticked to the left side, as in my first screenshot. How would I accomplish this?
I don't expect anyone to post code, just merely a push in the right direction as I'm totally lost on this.
Check this library, you can customize the UI in interface builder with consstraints and get what you want.

Custom Titlebar in a Cocoa Application

I need to create a (very) custom titlebar in a cocoa app. I read about the INAppStoreWindow library, but it seems it doesn't have the feature that I need. So here's what I have need to do (see image for clarification):
My titlebar is the thing between the green and red circle
The text (Text1 - Text3) are all images
The black circle with the exclamation mark is also an image
The grey area below the title bar is a webview. It expands from the left border all the way to the right edge of the reddish sidebar. (This is actually where why I think that the INAppStoreWindow won't work, as I cannot specify a width for the title bar)
The images should have an Action
Text1 through Text3 as well as the black circle load some URL into the webview
Red circle closes the app
My app has no borders and no shadows. Right know in order to be able to move the app I drew a Box element at the top where the title bar should be. I think I can draw something in it as well, but as I'm very knew to cocoa development here are my questions:
How can I draw some images in the Box element?
Is there a better element to draw the titlebar in?
I know that are two questions, but they are closely relatated. It's generally: How to draw a simple titlebar like this?
As the problem inside the titlebar is the same for every item I need to draw (they are all images) I belive there is a quite simple solution for that, but because I lack the experience of how to solve this I'd need your help. You can also point me the the right direction in the comments and I'll answer this question myself after I've got it right.

Positioning UI controls without relying on centers

I'm creating a sample login screen to practice Auto Layout. In portrait mode, it looks like this.
However when I rotate to landspace mode, it looks like this.
Below are the constraints I have set in this layout.
I understand why this is happening. It is because I have a constraint for the User ID UILabel [ Vertical Space(196) ]. How can I position the UIlabel+UITextField set slightly below the horizontal center line of the screen when turned to Landscape?
I assume I can set maybe the middle label to Horizontal Center in Container and then have the other 2 labels positioned relative to that one. But what I'm looking for is a way to position them without the help of center positioning in container. I want them to position slightly below the horizontal center line. How can I do that?
Thank you.
I don't think there's any way to do that in IB, without using the center property -- you could make your views appear below the center by putting another label above User ID, but with no text in it, so it will be invisible. Center that one, and have all the others positioned relative to it.
select all controls and select Top space to superview
Now select only textfields and select Widths Equally
This should work. If not, then let me know i will send you sample code or screens of constraints.

Shadow inside text on NSTextField/NSTextFieldCel

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.