ios - UITabBar images via the storyboard - ios

I have an image that I already use im my app like this via code:
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"building" ofType:#"png"]];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
and I wanted to reuse that image in the UITabBar. There is an image field on the Attributes inspector of the UITabBar image, and when I add the image name there (either building or building.png) the image does not render, but an image outline renders.
Would anyone know why that happens and how I can get the actual image to render?
Thanks!

Here you are using an, I guess, a rather small image as a pattern to form a color. For the UITabBar you need to have images of appropriate size. UITabBar knows, as many others does, appearance methods to modify UI elements. Look for UIAppearance in the docs for more infos. As far as your question is concerned have a look for setFinishedSelectedImage:withFinishedUnselectedImage under UITabBarItem.

Related

Setting UITabBarItem image in storyboard but different looking after run app

1) i add four png image in Assets.xcassets.
2)In storyboard, i embed in a Tab Bar Controller. Setting TabBarItem image.
3) But after running app. I found the image look seems a little different with my setting and i don't known why, can anyone know why and how to fixed? Waiting for you help,thanks
The reason why the image looks different is because it is being filled with plane colour, while your .png contains some white instead of empty background. UIImage has a property called renderingMode. This property can be default, AlwaysOrigin, AlwaysTemplate.
So for UITabBarItem the default rendering mode is AlwaysTemplate, that is why your image is being filled. And since your image contains a white background inside the search icon (where it should have contained no drawing) it gets also filled.
So you have two options:
1. Remove the white background from the icon.
2. Since you are using XCAssets, you can change the rendering mode in XCAssets attributes pane.
Here is where you can do that from XCAssets:
you need set UIImage.renderingMode,
try this
NSArray *items = self.tabBar.items;
UITabBarItem *item = items[0];
item.image = [[UIImage imageNamed:#"tabbar_recruit.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

How to achieve iOS 7 Tab bar icon design for iOS5/6

I want the tab bar of my App for iOS5/6 look just like on iOS7 without using Xcode 5. Is it possible to remove this gloss/shadow effect? I tried the famous -setFinishedSelectedImage:withFinishedUnselectedImage: code solution. But seems not to work with my case. I played around with these codes I have:
UIImage* icon1 = [UIImage imageNamed:#"discover_dg~iphone.png"];
UIImage* icon2 = [UIImage imageNamed:#"discover_lb~iphone.png"];
//UITabBarItem *updatesItem = [[UITabBarItem alloc] initWithTitle:#"Discover" image:icon1 tag:1];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *updatesItem = [tabBar.items objectAtIndex:1];
updatesItem.image = icon1;
[updatesItem setFinishedSelectedImage:icon2 withFinishedUnselectedImage:icon1];
[self.navigationController setTabBarItem:updatesItem];
First tab bar icons as the screen loads has the iOS6 look just like this with the glossy effect..
or this with the shadow effect..
I am trying to remove the gloss effect/shadow of the UITabBarItem on iOS5/6. When I click on a particular icon, the blue one will appear and when I leave(which in the unselected one) it will turn to GRAY, the ORIGINAL images which must FROM THE START appeared already as the screen loads/appear. But somehow, I got these set with the glossy ones..
or these with shadows..
Cheers in advance!
http://www.appcoda.com/ios-programming-how-to-customize-tab-bar-background-appearance/
This is the best solution.Use the storyboard.You just take the same code to AppDelegare.m
Good luck to you!
You can using the appereance protocol, in iOS7 is mostly made using new features, but from iOS5 appereance method make you able to do that. you just need to change the background (-setBackgroundImage:) image of the tabbar and each UItabbarItem for viewcontrollers from selected to unselected state( -setFinishedSelectedImage:withFinishedUnselectedImage: ).
There is also a tint property if you do not need to apply different image for each VC.
Check the doc here
Check also this answer

Add a custom image to UIRefreshControl [duplicate]

I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...

UIImage setBackgroundImage working on simulator but not on phone

I am trying to set the image of a UIButton I have as part of a custom UITableViewCell class to display images. The images load from a custom UIImageView class that is used to manage downloading and caching of the images. The method to assign the image to the button is contained within a delegate method for the custom UIImageView that is called when the image has finished loading:
UIImage *image = [[UIImage alloc] init];
image = ((LKCCachedImageView *)self.images[arrayIndex]).image;
[(UIButton *)self.buttons[arrayIndex] setBackgroundImage:image forState:UIControlStateNormal];
This works on the simulator but not on an actual device.
I've had some issues in the past updating the UI in delegate methods as some were not on the main thread but performing setBackgroundImage using dispatch_async on the main thread does not change the outcome.
Also, if I change setBackgroundImage to setImage the image displayed on the button is just a blue square. I'm not sure what to make of the behavior and I haven't seen anyone with anything exactly like mine.
Thanks,
Eric

How to customize UIRefreshControl with different image and position?

I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...

Resources