This is more like a design question but does anyone know how they made the Logo in the UINavigationBar look that good in the native iPhone app?
Does anyone know a tutorial?
Thanks in advance!
A UIViewController's -navigationItem property has itself a property called -titleView.
Set that titleView property of the currently displayed UIViewController's navigationItem to an embossed, semi-transparent icon like Twitter has done, and you're set.
You will load an image, and then put it in the navigationItem.titleView property on the view controller that will be inside the navigation controller.
UIImage *image = [UIImage imageNamed: #"header_logo.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
viewController.navigationItem.titleView = imageView;
Basically both answers were correct.
I'm just typing the code I've used. I like it better than #stevenhepting 's code :)
Just put this code in the viewDidLoad: method
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourPicture"]];
The perfect size for your image (in my opinion) is 80x40 pixels (width=80 / height=40).
Related
today I've an other problem: I add a background image to a table view and I like that stay stationary when the cells scroll. I found this
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"background.png"]];
here iPhone Fixed-Position UITableView Background.
but I'm not able to "translate" from Objective-c to Swift... so can anyone help me?
You could try something like this.
var view = UIImageView(frame: /*whatever you want your frame to be*/)
view.image = //whatever you want your image to be
tableView.backgroundView = view
I will add a label to an Image with addSubview but this does not work.
here the code:
.h
UIImageView *bgimage;
IBOutet UILabel *loadingLabel;
.m
loadingLabel.text =#"......";
bgimage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
bgimage.image = [UIImage imageNamed:#"Wait.png"];
[self.view addSubview:bgimage];
[bgimage addSubview:loadingLabel];
Screenshot:
"Tisch wird reserviert..." is the loadinglabel and is label shoud be in the UiImage
This is the "Layout" with the code from 2nd answer
Change your code as...
.h
IBOutet UIImageView *bgimage;
UILabel *loadingLabel;
.m
bgimage.image = [UIImage imageNamed:#"Wait.png"];
loadingLabel = [[UILabel alloc] init];
loadingLabel.frame = CGRectMake(0, 0, 100, 50);
loadingLabel.text = #"testing";
[bgimage addSubview:loadingLabel];
It will work.
You cant add a subview to a uiimageview, since drawRect: will never be called.
source:
"The "UIImageView class is optimized to draw its images to the display. UIImageView will not call the drawRect: method of a subclass. If your subclass needs custom drawing code, it is recommended you use UIView as the base class." from the apple docs:https://www.google.de/#bav=on.2,or.r_qf.&fp=90e2434f04e1ee9b&q=uiimageview+class+reference&safe=off
Solution:
As suggested, use a uiview to contain both the label and the imageview, and then bring the label to the top using -bringSubviewtoFront: of UIView. You can also use a UIViews backgroundimage to show your image and then have a label as a subclass in that view. Depends on the Situation you are in, i guess.
EDIT: YOU SHOULD READ THIS:
I misread the question, and it appears that you can add subviews to UIImageView, just like Zev pointed out in his comment. Right now im guessing that -bringSubviewToFront did the trick for you, and that the rest of my answer, while not really harmful, was unnecessary. Im sorry.
I am new to Xcode, and I am currently building my first app. I've searched long and hard to try and find the proper tutorial but I can't find one. I am looking for a way to be able to insert a custom background in my UITableViewController. I can change the color, but that is it. What I am looking to do is set my PNG image behind the static cells I've created, and drop the opacity on those cells so the custom image comes through. Can someone please give me a way to do this either through the IB (storyboard) or through the coding. Much appreciated!! Thanks in advance!
I think the easier and correct way is to:
[tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourimage.png"]]];
You can include this code in viewDidLoad to make it work.
for cell's background :, do this in willDisplayCell:atIndexPath: method
UIImageView *cellImageView = [[UIImageView alloc] initWithImage:[UIImageimageNamed:#"image.png"]]];
CGRect Frame = cell.backgroundView.bounds;
cellImageView.frame = newFrame;
[cell.backgroundView addSubview:cellImageView];
for tableview background , do this in viewDidLoad: method
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundPattern.png"]];
UIImageView *ivwCellBackground=[[UIImageView alloc]init];
[ivwCellBackground setImage:[UIImage imageNamed:CELL_BACKGROUNGIMAGE]];
cell.backgroundColor=[UIColor clearColor];
[cell setBackgroundView:ivwCellBackground];
[ivwCellBackground release];
ivwCellBackground=nil;
I'm using storyboarding and the Master-Detail Core Data template in Xcode4.
I want to set the background image for my tableView on the master view controller.
To do this was simple for the iPhone, I just did this in viewDidLoad of the MasterViewController.m:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
However, this doesn't work for the iPad; the default background is being shown instead in the master tableView.
I wouldn't think this was a splitViewController issue; from the perspective of the MasterViewController object, he should always have the same tableView, right? In fact, I know this is the case, because this code works on both iPad and iPhone, a line above the "backgroundColor" assignment, and this is using the same "self.tableView" object:
self.tableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"separator.png"]];
This is what it looks like on the iPhone, with both the separator and background image working (sorry, can't post pictures inline yet):
http://i.imgur.com/G7djz.png
And, using the same code, on the iPad:
http://i.imgur.com/8L0ZK.png
What do I have to set in order to set the background image on the master tableView?
You need to make the background clear in interface builder. Then, you need to say self.tableView.backgroundColor = [UIColor clearColor]; in your viewDidLoad. Finally, put a UIView behind it with the appropriate background color. For some reason, the background stuff is overridden in the UITableView itself.
Aha! I found the secret sauce:
UIImage *backgroundImage = [UIImage imageNamed:#"foo.png"];
UIView *backgroundView = [[UIView alloc] init];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
[self.tableView setBackgroundView:backgroundView];
The key is using [self.tableView setBackgroundView:...]instead of the property self.tableView.backgroundColor = ...
I am using a UITableViewController which uploads a table. I have a Nib File with UITableView in it.Now I want to set the background of the tableView either from interface builder or from the TableViewController to an image.
How to do that.
OK so I created an UIImage in my controller. Now when I add where do I need to add it.
When I try adding it and set the color of tableView to clearColor, it just shows me the Image and not the table although I make sure that image is being sent to back of all views.
Guys Please note that I am not dealing a UIView and adding a tableView as its subview But I am dealing with a UITableView .
Place a UIImageView behind the UITableView, then do this:
tableView.backgroundColor = [UIColor clearColor];
Somehow playing around I was able to find out a way.
self.tableView.backgroundColor = [UIColor clearColor];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData:imageData]];
self.tableView.backgroundColor = [UIColor clearColor];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"parentViewBackground.png"]];
the image size should be
2x - 640*960
1x - 320*480
the size smaller than above, it will be tiled.
The backgroundColor = [UIColor colorWithPatternImage: image] method rkbang outlines works great. Here is another method to achieve the same effect by adding a new view to the parentViewController. This would be useful if you want to mask other contents the parentViewController might have.
In your UITableViewController subclass, in -viewDidLoad insert:
//make a cool background image
self.tableView.backgroundColor = [UIColor clearColor];
UIImage *patternImage = [UIImage imageNamed:#"backgroundImage.png"];
UIImageView * backgroundImageView = [[UIImageView alloc] initWithImage:patternImage];
[self.parentViewController.view addSubview:backgroundImageView];
[self.parentViewController.view sendSubviewToBack:backgroundImageView];
//release the background image and image view (the backgroundImageView is still retained by the parentViewController)
[patternImage release];
[backgroundImageView release];
You may wish to keep track of the backgroundImageView so you can remove it or replace it. The code example above leaves it to the parentViewController to manage the new view. If you're loading and unloading this UITableView, you'll be leaking these UIImageViews with every load unless the parentViewController is releasing them at the same rate somehow.
What you can do is set the backgroundColor property of the tableview to [UIColor clearColor] and have a UIImageView of the same size and position underneath your TableView to show your background.
TableView properties include background color. Set this to clearColor; and put the image behind it. (In IB I think you'll have to delete the tableview add an image and then add your tableview back again)
if you're subclassing UITableViewController you get a tableview for free, no ivar or nib required, however since you're using a background I would stick with IB.
You can use the table-view's backgroundView. This worked for me.
[self.tableView setBackgroundView: [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"????.png"]]];
where ????.png is your background image.