i want to set a pdf file as a NSButton's image, and when i clicked the button,the button's color changed, just like the xcode's navigator editor. can some one tell me how to do this? thanks in advance!
![enter image description here][1]
Arguably you're better off converting the pdf to a png so you can handle it more easily.
But, you can create an image from the pdf and use that with the button:
NSPDFImageRep *pdfRep = [NSPDFImageRep imageRepWithData:pdfData];
NSImage *pdfImg = [[NSImage alloc] init];
[pdfImg addRepresentation:pdfRep];
Related
I am trying to add a background image to a table view. I am using Xcode and swift.
Use the .backgroundView property on your tableview object and set it with whatever UIImageView you want. UITableView Apple Reference Docs
tableView.backgroundView = UIImageView(image: UIImage(named: "something.png"))
You can also add image like this way also:
tableView.backgroundColor = UIColor(patternImage: UIImage(named: "your_image_name")!)
Add imageView to background layer and set what ever image to that image view .And set table view background color & cell color to clear.
I saw one of the Apple Videos mention that you can colour images via the code. All my searches on how to do this came up blank.
If I have a black vector image (pdf) saved inside Images.xcassets, how can I colour that image at run time?
Ideally it would be something simple like [UIImage setVectorColor:UIColorBlue] but I'm sure there could be more to it!
You have to set all vectors image as Template Image on Render options in the xassets. (http://i.stack.imgur.com/oTuDC.png)
After, you can set the color in the uiimageview which contain your image with method :
[imageView setTintColor:[UIColor redColor]];
I have a View to get and set image from photo gallery.
I want to call the image from another view and set the uiimage as background.
What is the best method to make the image stay as a background like iPhone default background feature?
My codes are modified version from here: http://blog.hanpo.tw/2012/01/uiimagepickercontroller-and-simple.html
The best way is to use a UIImageView :
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentOfFile:#"path/of/myImage.png"]]
You can pass the path to your image as an argument and store it or copy the file under the name "background.png" for example, and each time you change it you delete the file and create the new "background.png".
I am trying unsuccessfully to get my custom retina images to display in my custom iOS5 TabBar.
I have 4 items in my TabBar, I have set the selected/unselected image to contact#2x.png which has a resolution of 160px x 75px. I figured 4 of these 160px width images would accommodate the 640px retina width nicely.
You can view my contact#2x.png here
https://lh4.googleusercontent.com/-afHulbEcxNE/TuPe-YIj91I/AAAAAAAAAII/lCojphAxF9w/s160/contact%2525402x.png
I have set all the items programtically as seen below.
UIImage *selectedContact = [UIImage imageNamed:#"contact#2x.png"];
UIImage *unselectedContact = [UIImage imageNamed:#"contact#2x.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
[item0 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
[item1 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
[item2 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
[item3 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
At runtime I can see that the scale is set to 1
Why isn’t the 2 being picked up off the image suffix? The tab bar is huge, and isnt scaled.
Please see the simulator screenshot below…
https://lh5.googleusercontent.com/-A5oxZprlDhU/TuPfAlG_HQI/AAAAAAAAAIc/mIwHXOPZSrE/s735/simulator.png
My other retina images for my app icon and default icon are working.
Thoughts? I am driving myself nuts ☺ Thanks in advance.
JoePasq is wrong, he obviously is not up to date with the latest iOS5 appearance customisation API. Your problem could be that you specified the #2x in the filename, just pass "contact.png" to imagedNamed...
[UIImage imageNamed:# "contact.png"]
Have you looked at the documentation for customizing the appearance of UITabBar?
You should consult this tutorial by Ray Wenderlich about using the UIAppearance APIs.
His code is this:
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:#"tab_select_indicator"]];`
Note that the customization happens on the Tab bar, not the tab bar items—assuming it’s the same customization for each one.
As nbransby said you do not use #2x in the filename.
Prior unedited answer:
From the documentation:
The images displayed on the tab bar are derived from this image. If this image is too large to fit on the tab bar, it is scaled to fit. The size of an tab bar image is typically 30 x 30 points. The alpha values in the source image are used to create the unselected and selected images—opaque values are ignored.
Your icons should be 30x30 px for normal resolution and 60x60 px for retina resolution. They should also be a solid color, the tab bar adds the coloring.
I have to make a prototype application where I superimpose a small image over the file icons of a given folder.
Let's say I have a folder /MyDocuments/
and there are three files /MyDocuments/Doc1.rtf /MyDocuments/Doc1.pdf and /MyDocuments/Doc1.jpg
and I have an image myicon.png, now I have to superimpose this image myicon.png over the file icons of all the three files present in /MyDocuments/
I understand that I can use the methods in NSWorkspace sharedWorkspace to get and set the file icons for these files, but I have no idea how to use the image myicon.png and superimpose it over the existing icons of these files.
If anyone has seen the Dropbox application (dropbox.com), then it is similar to the way you see changed icons in your dropbox folder
I assume it would be done using NSImage but I have no idea how to do it.
Note: the image myicon.png will only occupy the top left part of the original icon of these files i.e. the image should not completely overlap with the existing icons but only the 1/4th portion on the top left should be occupied.
Lock focus on the file icon, then draw the badge icon, then unlock focus. You may want to do this to a copy of the file icon, and hang on to the unbadged original.
If the badge is one of the standard badges that come with Mac OS X, don't copy the badge into your app—it'll look outdated if Apple ever changes it. The standard badges are named in IconsCore.h; you can wrap any of those types in a string using the NSFileTypeForHFSTypeCode function, then pass that string to NSWorkspace's iconForFileType: to get the standard badge as an image, from which point you can do the above.
As a supplement to Peter Hosey's answer, here is some slightly modified example code from:
http://cocoadev.com/forums/comments.php?DiscussionID=221
NSImage *origImage = [sourceImage copy]; // Copy to avoid modifying the original.
NSSize previewSize = NSMakeSize([origImage size].width / 4.0, [origImage size].height / 4.0);
NSImage *previewImage = [[NSImage alloc] initWithSize:previewSize];
[previewImage lockFocus];
[origImage drawInRect:NSMakeRect(0, 0, previewSize.width, previewSize.height)
fromRect:NSZeroRect // Draws full image.
operation:NSCompositeSourceOver
fraction:1.0];
[previewImage unlockFocus];