I am using a UITabBarController in my application (for iPhone 5). When i am trying to set an image on the TabBAr, the image shows a line. I have seen two questions similar to mine, but did not understand the solution.
Here's how I am adding the image:
UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
The dimensions of my current image is 320X64 pixels.
How to resolve this issue??
write this in appdelegate.m didfinishLanching method
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tab_select_indicator"]];
In iOS 6 and aboove the UITabBar has a shadow image, if you want to disable it you can just call yourTabBar.shadowImage = [UIImage new].
In your case tabBarController.tabBar.shadowImage = [UIImage new]
Yes, it is possible to make it exact size.
Use this code if you are just using a UITabBar inside your view:
Type :1
UITabBar *tabBar = [[UITabBar alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 60)];
[self.view addSubview:tabBar];
UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tabBar.png"]];
tabBar.backgroundImage = tabBarView.image;
Presently my image size is 320 x 5
Type 2:
If you are using a UITabBarController then use it like this
UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tabBar.png"]];
UITabBarController *tabController = [[UITabBarController alloc]init];
tabController.tabBar.backgroundImage = tabBarView.image;
Here are the screen shot for both.
Related
So I am trying to set a universal back button image for every time the back arrow appears in the UINavigationController. However, every time I attempt to implement, the image gets skewed and extended. The original image is a simple back arrow. However, the back button image (that does work universally) is getting skewed as shown:
I have tried using the following code in my AppDelegate – still no luck.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Attempt 1
[[UIBarButtonItem appearance]
setBackButtonBackgroundImage:[UIImage imageNamed:#"Back"]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
// Attempt 2
UIImageView *buttonBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
buttonBack.image = [UIImage imageNamed:#"Back"];
[[UIBarButtonItem appearance]
setBackButtonBackgroundImage:buttonBack.image
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
You need to set the contentMode of the UIImageView of your back button.
Use this code to set the image to fit the UIImageView's frame and maintain it's aspect ratio of the image:
// Attempt 2
UIImageView *buttonBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
buttonBack.image = [UIImage imageNamed:#"Back"];
// this line sets the aspect mode
buttonBack.contentMode = UIViewContentModeScaleAspectFit;
[[UIBarButtonItem appearance]
setBackButtonBackgroundImage:buttonBack.image
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
The answer was a lot simpler than expected. Drop some of the additional code and trim it down to its barebones – you come out with something like this (in the AppDelegate, didFinishLaunchingWithOptions):
// Custom Back Button
UIImageView *buttonBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
buttonBack.image = [UIImage imageNamed:#"Back"];
buttonBack.contentMode = UIViewContentModeScaleAspectFit;
Something weird and frustrating is happening with the UINavigationBar on iOS7. I'm trying to add an image like this:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Logo_Small.png"] forBarMetrics:UIBarMetricsDefault];
The result is that the lettering of my header -- the Hebrew letters -- repeat all over the navigation bar.
I tried all four options for the UIBarMetrics flag, but with the other three the logo just disappears. I also set the image size to 320x64, as per the documentation. But nothing seems to do the right thing, and I'm on the verge of giving up using a logo and just have a controller.title.
Do the below:
UIImage *gradientImage = [[UIImage imageNamed:#"Logo_Small.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(-4, 300, 10, 300)];// play here
[[UINavigationBar appearance] setBackgroundImage:gradientImage forBarMetrics:UIBarMetricsDefault];
you can do like this
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,44)];
iv.image = [UIImage imageNamed:#"Logo_Small.png"];
self.navigationItem.titleView = iv;
Use this,
UIImage *navBarImage64 = [[UIImage imageNamed:#"Logo_Small.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:navBarImage64 forBarMetrics:UIBarMetricsDefault];
If above is not working then add imageview in your NavigationBar as below code. it work.
UIImage *image = [UIImage imageNamed: #"NavigationBar#2x.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
imageView.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationBar addSubview:imageView];
You code is actually works. The problem is that you are probably calling it after UINavigationBar was added to screen.
To verify that your code is working you can try to put into AppDelegate's didiFinishedLaunchingWithOptions.
To customize navigation bar with Image use this,
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"ImageName.png"] forBarMetrics:UIBarMetricsDefault];
I am using UIToolbar in iPad App,How can I remove the gradient background from it? Below is my Code.
aToolbar.barStyle = UIBarStyleBlackTranslucent;
aToolbar.tintColor = [UIColor blackColor]; toolbar.alpha = 1.0;
You need to set image in UIToolbar so remove Gradient.
My suggestion is please set image and create custom UItoolbar.
For that code is below.
UIImage *gradientImage44 = [[UIImage imageNamed:#"imageName.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set the background image for *all* UINavigationBars
[[UIToolbar appearance] setBackgroundImage:gradientImage44
forBarMetrics:UIBarMetricsDefault];
So I am try to set a background image for a navigation bar in MonoTouch. The image will be the same everywhere. How would i do this?
In the viewdid load: NavBar.SetBackgroundImage(UIImage.FromFile ("btn-title-bar.png"));
doesn't work.
Try
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"btn-title-bar.png"] forBarMetrics:UIBarMetricsDefault];
In c# land that is:
UINavigationBar.Appearance.SetBackgroundImage (UIImage.FromFile ("btn-title-bar.png"), UIBarMetrics.Default);
Try this below code.
UIImage *image = [UIImage imageNamed: #"NavigationBar#2x.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
imageView.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationBar addSubview:imageView];
if you want to put different images on every page then write this method in view did load on every page..
UIImage *image = [UIImage imageNamed: #"logo.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
self.navigationItem.titleView = imageView;
and if u want single image on every page then write this code in delegate.m.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"logo.png"]
forBarMetrics:UIBarMetricsDefault];
So I have an navigation bar I would like to customize and center no matter what I do I either get the image tiling like so.
Here is the code i am using to set the self.navigation.titleView in my UITableControllerView
self.navigationItem.titleView = [self titleView]; // happens in viewDidLoad
- (UIView *)titleView{
UIImage *headerImage = [UIImage imageNamed:#"header#2x"];
UIImageView *containerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, headerImage.size.width, headerImage.size.height)];
return containerView;
}
Thanks.
UIImageView *imgtitle = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 25)];
[imgtitle setContentMode:UIViewContentModeCenter];
self.navigationItem.titleView = imgtitle;
imgtitle.image = [UIImage imageNamed:#"logo.png"];