How to display image behind TableView in Xcode - xcode

I want to add a background image behind my table view.
I have my file staticTableControl.m where I populate the table and I have added
-(void)viewDidLoad{
self.tableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"disk2.jpg"]];
[super viewDidLoad];
}
at the top, but the image doesn't load - please can someone advise me what else I need to do?
Thank you
There have been some other questions about background images for tables, but I couldn't find one specifically for this.

A good solution is to change the tableview background color to transparent and add an imageview behind it

Related

Add Background Image to UITableView programmatically

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.

What is the best way to show the content below the NSWindow?

Here is the UI Mock up:
The blue background is the screen, and the red is a NSWindow, and I would like to build a NSView? (Yellow) that is on top of the NSWindow. The NSView is basically transparent, so that it can shows the live information behind the red NSWindow. What is the best way to implement the NSView? Any suggestions? Thanks.
***One more remarks, the Yellow view is not only need to transparent, but also need to use for analysis. So, if I can get the raw data or transfer it to NSImage will be great.
My 2 cents. Let your view be an NSImageView. You can draw the background to be clear
- (void)drawRect:(NSRect)rect
{
[[NSColor clearColor] set];
NSRectFill(rect);
}
You could then convert whatever you draw in there into an image by using [NSBitmapImageRep initWithFocussedViewRect:]. Would something like that work?

NSImage is always being scaled and looks bad

I want to create an NSImage of an NSScrollView object, so I can use the flat graphic for animation purposes.
When I render my scrollview object into a graphic and add it back to my window, it works but looks really bad like it's been scaled to 99% or something. I want the image to not be scaled and 100% pixel accurate. (Note: the image isn't scaled, it's the same size, it just looks like it's been poorly rescaled - the text looks rough and poor compared to the view onscreen in the scrollview)
My code:
(scrollView is my NSScrollView object)
NSData *pdf = [scrollView dataWithPDFInsideRect:[scrollView bounds]];
NSImage *image = [[NSImage alloc] initWithData:pdf];
NSImageView *imageView = [[NSImageView alloc] initWithFrame:[scrollView bounds]];
[imageView setImage: image];
[mainGUIPanel addSubview: imageView];
I've tried a heap of things, messed with pixel sizes, bounds, used IB to create the destination NSView and put the image inside that but just cannot get the image to not look bad. Any ideas?
Edit:
I tried writing the pdf data to a pdf file and viewed it, and it looked ok. So the bitmap image is being captured ok, it's just on the display that it looks like it's being scaled somewhat.
Edit2:
Also tried getting the bitmap like this:
NSBitmapImageRep *bitmap = [scrollView bitmapImageRepForCachingDisplayInRect:[scrollView bounds]];
[scrollView cacheDisplayInRect:[scrollView bounds] toBitmapImageRep:bitmap];
NSImage * image = [[NSImage alloc] initWithSize:[bitmap size]];
[image addRepresentation: bitmap];
Same results - the bitmap looks exactly the same, bad and scaled when displayed.
This leads me to believe that capturing the bitmap data either way works fine, it's creating the view and rendering the image that is doing the scaling. How can I make sure that the view and image are shown at the correct size and scaling?
Edit3:
Ok, I started a new blank project and set this up, and it works perfectly - the new imageview is identical to the grabbed bitmap. So I suspect my issue is stemming from some rendering/compositing issue when drawing the bitmap to the view. Investigating further...
It turns out the issue stems from the scrollView that I am rendering from. This has a transparent background (Draw Background is off in IB) and the text is the scrollView looks good. If I turn "Draw Background ON", with a transparent background color, the text is rendered badly, exactly as it is when I capture the image programatically.
So, in my app, even though Draw Background is off, the scrollView image is captured as though Draw Background is on. So I need to understand why the text is rendered badly when Draw Background is on and set to transparent, and hopefully this will lead me towards a solution.
Also tried creating an NSClipview with background drawing turned off and putting the bitmap view into that, but it sill renders the same. I can't find a way to render the transparent image to the screen without horrible artifacting.
Ok, I've found a solution. Instead of getting a grab of the transparent background scrollview object itself, I'm instead getting a grab of the parent view (essentially the window background), and restricting the bounds to the size of the scrollview object.
This captures both the background, and the contents of the scrollview, and displays correctly without any issues of transparency.

Removing Glossy Effect on UITabBar

I know this is a common question but it's quite different in my case.
I want an image to be placed when the bar is active and I've done that successfully using these code under didFinishLoadingWithOptions method [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabbar-active.png"]];
And that's what my app looks like
Now I just want to remove that glossy effect, not the blue image on the bar
Thanks in advance!
After digging a little bit, I found the solution for the same. You simply need to create an UIImage object with empty image.
[yourTabbar setSelectionIndicatorImage:[[UIImage alloc] init]];
Thats it :)

UIView backed by CATiledLayer in UIScrollView doesn't scroll initially

I'm adding a CATiledLayer backed UIView in UIScrollView.
When the view is first loaded, I'm trying to fit the UIView, by setting the zoomScale of UIScrollView - this fits the UIView and the layered contents.
I'm having a method to fetch the tiles of image and I'm rendering them in drawLayer:inContext:
Now even if the contentsize of scrollview/frame of CATiledLayer view is greater than UIScrollView, it doesn't scroll initially.
The moment I try to zoom by pinching the screen, I'm able to scroll perfectly.
I can't scale the CGContext in drawLayer:inContext, since the context I receive is of a tile and not whole image and I have 20 tiles which make up my image.
At the end of the initWithFrame of the PDFScrollView i added the line:-
self.zoomScale = 1.0;
This worked for me.
The code is pretty much doing the same stuff as apple example
http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010281-Intro-DontLinkElementID_2
which also doesnt scroll on loading

Resources