How to draw colors over a UIImage - objective-c

I was wondering how you draw colors over a UIImage in objective-c?
The same way that snapchat does it.
I want to make a button that enables the painting with a scroll bar to change the color.
Does anyone know the way that snapchat implements the paint feature?

There's no out-of-the-box way to do this. You'll want to (a) track touch positions over time, and (b) draw them on the screen in a user-selected colour.
There are open-source implementations of this idea, for example https://bitbucket.org/nwoolls/simpledrawing/wiki/Home
Also a bunch of color-picker components here:
https://maniacdev.com/2011/11/open-source-ios-color-picker-components-roundup

Related

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.

Cocoa-Touch: use button or UIImage for clickable image?

I'm building a iOS app which involves lots of photos displayed as rectangular areas on the screen. You can click on that area and see a bigger version of the photo. Kind of like those wallpaper apps, where you first see a grid layout of small wallpapers and then you can go in to see a bigger version.
So, I'm wonder what's the pros/cons in terms of memory usage and scalability between setting them up as UIButton (w/ background) and UIImageView?
I'd use an UIButton. It's easier to use as a user because it's made for touching them. Since UIImageView directly inherits from UIView it doesn't really know targets and selectors. So you'd have to implement this using touchesBegan:withEvent:. UIImageView is more efficient at drawing pictures though. UIButton already knows that so you'd only have to set the picture.

UIButton border along rounded rect

I have a button and its type is UIButtonTypeRoundedRect, but its border does not go along the rounded corner. How can I curve the border.
Check out this blog post I recently wrote: UI Polish in An Instant
You're on the right track accessing the button's layer property, but there is more you need to do (for example, to get rounded corners, add deleteButton1.layer.cornerRadius = 10), and more you can do, all without extra images.
Images are the recommended method for creating custom buttons. Apple's built-in buttons are basically only there for prototyping.
You could also create a subclass of UIButton and then override the methods for drawInRect and provide custom drawing code, probably using CoreGraphics. However, it is still much cleaner in code and more efficient at runtime to just use images.

Looking for a vertical NSToolBar lookalike

I'm looking for an NSToolBar type of object to use in my application. I need it to be vertical and to look nice. The buttons on the object do not need to be repositioned or customizable like the NSToolBar it, but I would like the same look and feel the NSToolBar has, just vertical.
I've tried the google route, but I'm not really sure what to search for when it comes to looking for obj-c objects or examples.
I know seeing as what I want is basically a static set of buttons along the side of my window I could just use a bunch of buttons, but it doesn't have the nice seamless look that the NSToolBar does.
Is there something out there similar to what I'm looking for? Is there a repository of obj-c objects or a nice collection of them on a site that I'm just not finding?
It wouldn't have much in the way of functionality, but if you check the 'Textured' box (under 'Appearance') in Interface Builder of an NSWindow, it will make the whole window look like a toolbar. Dropping a well-placed NSBox (set to 'Custom', and with a fill color of the background of a window-or-so) on top of the window leaving only a strip for what would look like a toolbar, you would have a visual approximation, although without any functionality of an NSToolbar whatsoever. Buttons would all have to be done manually, etc, etc.
However, I must caution you that this sounds like a major violation of the HIG. If you are trying to make something twitterish, I won't dissuade you, but it is a sort of crosroads there's no need to cross until Apple decides which path it is going to take.
The toolbar itself wouldn't be too tricky, but if you wanted to allow customization, that would be tricky. Since you didn't mention customization (or showing/hiding) all you really want is a vertical bar of buttons and a background color that matches the window color.
Make your window a textured window, using NSTexturedWindowMask, then create a subclass of NSView with the dimensions you want, drawing its background to match the window background color.
-(void)drawRect:(NSRect)dirtyRect {
[[[self window] backgroundColor] set];
NSRectFill(dirtyRect);
}
The buttons will just be subviews of this view.
Like I say, customization and showing/hiding make this is much harder task to achieve.

Howto draw a rect on screen. NSOpenGLContext vs transparent NSWindow + custom NSView

I'm reading pixels from an area of the main screen via NSOpenGLContext. Now I would like to draw a rect around that area to indicate where it actually is.
How would I do this?
My first thought was the "Cocoa way": create a transparent fullscreen NSWindow and a custom NSView to draw the rectangle path. But that feels a bit too complicated. Isn't it possible to draw directly on the NSOpenGLContext?
If you want to draw over elements not inside your application the floating window is the only correct way. There’s really no complication except mapping positions properly, which is easy to do with the coordinate-space conversions available on NSView and NSWindow.