custom navigation bar in xcode is cutting the image - xcode

/*enter code here */ UIImage *image = [UIImage imageNamed: #"top-bar.png"];
UIImageView *imageview = [[UIImageView alloc] initWithImage: image];
// set the text view to the image view
self.navigationItem.titleView = imageview;
I am using this code for custom navigation bar but the image is cutting out . Although the image width is same as device width.
Any idea, how to solve this.

The titleView property only covers title area of the navigation not the complete navigation-bar.

Related

Xcode UIImageView in UIScrollView IOS

can you help me? I would like add background image with scrolling, because my background image is too high. How can I do this? I add UIScrollView and into I add UIImageView but it doesnt scroll.
Thank you for replies.
Here is working code:
- (void)viewDidLoad
{
[super viewDidLoad];
//create scrollView and set the frame to the size you want.
//In this example the scrollView frame is the whole ViewController size
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setBackgroundColor:[UIColor clearColor]];
//create a UIImage,set the imageName to your image name
UIImage *image = [UIImage imageNamed:#"YourImageName.png"];
//create UIImageView and set imageView size to you image height
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, image.size.height)];
[imageView setImage:image];
//add ImageView to your scrollView
[scrollView addSubview:imageView];
//set content size of you scrollView to the imageView height
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, imageView.frame.size.height)];
[self.view addSubview:scrollView];
}
If you want the scroll view to scroll, set the content size to be bigger than the scroll view frame.

IOS 7: Tabbar Item Icons selected images not appearing right

I am developing an app in IOS 7 and I am setting the custom images for tabbar icons. Here is my code:
UIImage *musicImage = [UIImage imageNamed:#"monitor"];
UIImage *musicImageSel = [UIImage imageNamed:#"11"];
musicImage = [musicImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
musicImageSel = [musicImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Notifications" image:musicImage selectedImage:musicImageSel];
My problem is that when I select any tab in the tabbar the image just appears to enlarge.
I am attaching screen shot for more clarification. I just want the image to be in the tabbar. And also both the images are of 50X50px in size.
Maybe try manipulating imageInset property. For me (5,0,-5,0) were ok - but I didn't use titleLabel
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Notifications"
image:musicImage selectedImage:musicImageSel];
self.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5,0);

Setting the height of the UINavigationBar

I have set a UINavigationBar background image to an image with a height of 68px as opposed to the default 44px. Now the image is shown fine, but the content in the UINavigationController is overlapped in the first (68-44)px = 12px by the header image.
How do I fix this? I have tried setting the frame of the UINavigationBar without luck.
Thanks, Caspar.
This is my code (AppDelegate.m):
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.frontTableViewController];
UINavigationBar *navBar = navigationController.navigationBar;
[navBar setBackgroundImage:[UIImage imageNamed:#"header"] forBarMetrics:UIBarMetricsDefault];
self.window.rootViewController = navigationController;
try setting the image for the navigationbar this way
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myNavBarImage.png"]];
or have a look at this Answer

Add programmatically UIImageView adapted for 3.5 and 4 inch

I would like to add an UIImageView to this view. Can anyone help me please?
The problem is the compatibilities for 4/3.5 inch
I tryed this
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height)];
[imageView setImage:[UIImage imageNamed:#"test.png"]];
[self.view addSubview:imageView];
but the image comes out of the screen!
Thank you!
Controllers are created with a default size and resized after viewDidLoad. Depending on where you are creating your image view, it could cause you problems
Add this code:
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Also make sure that you don't have other views that you don't want to step over with your image, like the bottom toolbar

UIImageView to UIImage

I have UIImageView contains static image, I want to get this image and set it under UIImage variable.
How can I do that?
UIImageView *imageView = ... // Set from somewhere
UIImage *image = imageView.image; // Get the UIImage.
UIImage *otherImage = [UIImage imageNamed:#"Icon.png"]; // Load another image.
imageView.image = otherImage; // Change in the image in your UIImageView.
UIImageView Class Reference at developer.apple.com

Resources