How can I use the default background image for a UIView?
theView.backgroundColor = [UIColor groupTableViewBackgroundColor];
You can do something like this with UIView class:
[yourview setBackgroundColor:
[[UIColor alloc]
initWithPatternImage:[UIImage imageNamed:#"yourpattern.png"]]];
I always prefer using Interface Builder and just put a UIImageView occupying all UIView and send that UIImageView to back though...
if you are using Interface Builder you can choose "Group Table View Background Color" in the inspector of your UIview.
i just found out this when I read the above answer to your problem (i was trying to do that exatly :P)
Related
There is a way to do not show the UITableView in Kal, i.e., just the calendar (little squares) interface?
Thanks in advance!
You'll have to do this in code as Kal does not expose a way to do it natively. You'll have to edit the code in KalView.m.
Just comment out the below line in KalView.m addSubviewsToContentView: (line 179 in the GitHub repo I'm using).
[contentView addSubview:tableView];
This will result in a black box which fills the rest of the parent view. If you want a different color then you need to set a different color/background on the contentView or add your own UIView with the same frame as tableview. You could do something like this.
UIView *myView = [UIView alloc] initWithFrame:fullWidthAutomaticLayoutFrame;
myView.backgroundColor = [UIColor redColor];
[contentView addSubview:myView];
This will replace the tableView with a plane UIView with a red background.
I'm very new to iOS programming.
I'm trying to set the toolbar background to a custom image.
I'm also using storyboards.
How do I go about that?
Do I edit UIToolbar in the UI Kit framework? Do I need to change something in Storyboard?
Thanks,
You can use UIToolbar's built-in -setBackgroundImage:forToolbarPosition:barMetrics: method:
// portrait
[yourToolbar setBackgroundImage:[UIImage imageNamed:#"YourToolbarBkg-Portrait.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
// landscape
[yourToolbar setBackgroundImage:[UIImage imageNamed:#"YourToolbarBkg-Landscape.png"] forToolbarPosition:UIToolbarPositionAny barMetrics: UIBarMetricsLandscapePhone];
YourToolbarBkg-Portrait.png will be 320x44 bkg image for portrait mode
YourToolbarBkg-Landscape.png will be 480x32 bkg image for landscape mode.
UIToolbar inherits from UIView. This just worked for me:
[topBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:BAR_BKG_IMG]] autorelease] atIndex:0];
UPDATED
topBar ------ is the outlet of the UIToolBar u are using
use this code where u are creating ur UIToolBar the class which implements the UIToolbar..
plus tell me y r u using Toolbar whats ur main purpose for it
Instead of editing UIToolBar, why not create a UIView of the same size and skin that however you would like? That would be easier if you are new.
Or if you want to override UIToolbar:
#implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: #"image.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
#end
Had a right faff with background images for ToolBars and NavBars. I know setting the background image of a NavBar and ToolBar is generally a doddle. But, when you're presenting modal VC's, for some insane reason, where a NavBar is being added and you DO change the background image, it appears to double in size. Altering the height has strange results.
My issue was where I was using a NavController all over my App, but needed a modal view for one or two aspects of it. Simple enough. However, I needed either a NavBar or ToolBar type header with a Done button to pop the VC off the stack. Again, not an issue. But I needed the NavBar or ToolBar to look the same as everywhere else in my App.
I settled on a ToolBar, seeing as the VC was being presented modally. So, there my ToolBar sat, in typical Apple-blue. Nice, but not how the rest of my App looked, where a blackened image was being used for each NavBar. Using the iOS 5 appearance proxy, I altered the background image of the ToolBar. And this worked. But, unless I had the UIImage in exactly the proportions and size expected by the Tool Bar, I was in a pickle. The image simply did not look right at all. So, I decided to create a UIIMageView, where I could control the content mode, then insert a subview onto the toolBar.
Take a look at my code below.
UIImageView *toolbarImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:NAV_BAR_BACKGROUND]];
[toolbarImageView setFrame:[self.IBOToolBar bounds]];
[toolbarImageView setContentMode:UIViewContentModeScaleAspectFill];
[self.IBOToolBar insertSubview:toolbarImageView atIndex:1];
It's a bit of a fluff but I do hope this helps someone alter the image on their ToolBar.
NAV_BAR_BACKGROUND can be defined as follows:
#define NAV_BAR_BACKGROUND #"navBarBlackMattDarkSquare.png"
I am having trouble explaining this to myself but here is my best attempt.
I have a rootViewController that has a unique background imageView (placed in IB). When the user advances from that screen a navigationController is loaded in with a standard background color and can advance through the next screens. Is it possible to have just one image always stay as the background, i know i can use:
self.tableView.backgroundColor = [UIColor clearColor];
to allow the background to show through, but for some reason when i do this i see the first background image(the unique one), not the one that i have added to the Navigation controller.
This is the code that i use to add a bg to the nav controller:
UIImage *img = [UIImage imageNamed:#"v3_default_bg.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.frame];
bgView.image = img;
[appDelegate.navigationController.view sendSubviewToBack:bgView];
My question is this, is it possible to apply a non-unique background to the navigationController.
I also tried addSubview: instead of sendSubviewToBack: but that just blocks out my content. Could anyone lend me some thoughts? Thanks.
[appDelegate.navigationController.view sendSubviewToBack:bgView];
does not add the subview to the navigationController.view. You need to add it, then send it to the back:
[appDelegate.navigationController.view addSubview:bgView];
[appDelegate.navigationController.view sendSubviewToBack:bgView];
hide the navigation bar and then put Ur view there....
I know this is a very beginner question, but I'm obviously a beginner. I have already made a my TabBar but I want to set the background of one of the views as a (jpg) I created. I need to add the background in code (not IB) so that I can allow rotation and resizing when the iphone is rotated.
-thanks
You need to use a UIImageView, which is a subclass of UIView. You can create it as follows:
UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myImage.jpg"]];
[self.view addSubview:myImage];
[myImage release];
...so here I've created a UIImageView that uses a JPG called 'myImage' (it will automatically resize the view to fit the image), added it to my view controller, and then cleaned up my memory.
You can try this one to set an image as a background for a view programmatically:
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"imageName.png"]]
Add an instance of UIImageView to your view, and set it's image to an instance of UIImage created using your file.
You can add the image view in IB or in code -- there's nothing about doing it in IB that would prevent you from resizing, rotating, etc.
In iPhone I need to set the background view of a UITableview. From 3.2 SDK I can in code use something like:
[self.tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"mycustombackground.png"]]];
But how can I do the same in interface builder? It would be great if I could just set the background view directly in interface builder. But can't seem to find this property, where is it?
Thanks!
Add a UIImageView behind it, put the image in that and set the tableview to transparent:
self.tableview.backgroundColor = [UIColor clearColor];