iOS using image background for Button - ios5

i have that image background with transparent part and i went using for my buttons without
transparent part and if possible with interface builder

By the sounds of it you are possibly using the UIButtonTypeRoundedRect style, but UIButtonTypeCustom may be more suitable. You can change this within Interface Builder's inspector window.
still i refer this link http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

btnImage = [UIImage imageNamed:#"image.png"];
[btn setBackgroundImage:btnImage forState:UIControlStateNormal];
[btn setTitle:#"Title" forState:UIControlStateNormal];
or you can directly set background image from your xib by changing it into custom type.

Related

How to make image behind invisible button look like it was pressed down?

Hi I have a couple of images that are covered by an invisible button. Is there a way that I can make it look like the images were pressed down when I press the invisible button? Thanks!
You can put the image directly onto the button, you dont need a seperate UIImageView.
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setBackgroundImage:image forState:UIControlStateSelected];
The are a few more UIControlState constants.
Take a look at the docs:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/c/tdef/UIControlState

Custom uibarbuttonitem image to blend with background

I am making a custom UI for Navigation bar and I have a question exactly as asked in this post
Custom background/transparent background on UIBarButtonItem?
In StoryBoard I tried every sort of combination to make my UIbarbuttonitem tint transparent or clear color but I still see this ugly black button (see then + sign). How can I achieve the effect of transparency so that it looks like my button is blended in with the background?
My screenshot
Some other app screenshot. Look how nice this looks?!
Note here the + image is my own custom png img of 20 x 20 pixels with transparent/blank background.
You can achieve that and more using the new appearance API introduced in iOS 5.
Basically you set the appearance for your UI once and it gets reflected in the whole program.
Here is an example for the UIBarButtonItem:
// You can also use stretchable images
UIImage *image = [[UIImage imageNamed:#"myCoolBarButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
If you cannot use iOS 5, then you have to build those programmatically like this:
// Create a custom button with an image
UIImage *image = [UIImage imageNamed:#"myCoolBarButton.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
// Create a custom UIBarButtonItem with the button
UIBarButtonItem aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
Anyway, here are a few links with good tutorials on the appearance subject
User Interface Customization in iOS 5
How To Make Your App Stand Out With The New iOS 5 Appearance API
EDIT:
Just for clarification, it is much easier to do with custom images than playing around with colors, gradients and transparency.
You can't do it with tint. You will have to set both the backgroundImage of the navigation bar and the backgroundImage of the bar button item, so that they harmonize as desired.
When drawing the background image of the bar button item you may have to draw the entire button including the rounded rect outine and the shadowing of the rounded rect outine, but this is not difficult, and when you've done it once you've reusable code forever.
I think your png image with + sign does not contain alpha channel. I have transparent image and it's working perfectly fine for me.

limiting the touchable area in a UIButton in IPhone?

I have three custom buttons with non-rectangular images close to each other in my view. Then I have a problem with touchable area's of each button overlap with other buttons. So how can I limit the touchable area of each buttons to get the corresponding actions?
You can overwrite -pointInside:withEvent:, that internally will be used for hit testing.
A nice project using this technique is OBShapedButton, where transparent pixel will not trigger a hit.
Use two components. A UIImageView with a smaller UIButton on top.
You should create custom Type Buttons and add required images on each using this code:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:#"image.png"] forState:UIControlStateNormal];
[btn setFrame:frame];
Creating buttons with images this way will not result in overlapping images issues !!

UIButton selection color [duplicate]

This question already has answers here:
Is it possible to change a UIButtons background color?
(17 answers)
Closed 8 years ago.
I am drawing custom a UIButton and want to set the blue color when it is highlighted. How can I achieve this?
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setBackgroundImage:[[UIImage imageNamed:#"test.png"] stretchableImageWithLeftCapWidth:100 topCapHeight:0] forState:UIControlStateNormal];
You can do following to set images for your state (normal/highlight/selected). You have to have images.
[downButton setImage:[UIImage imageNamed:#"white.png"] forState:UIControlStateNormal];
[downButton setImage:[UIImage imageNamed:#"blue.png"] forState:UIControlStateHighlighted];
Ya, you can create a 1px by 1px "blue colored" image and use the following:
[yourButton setBackgroundImage:[UIImage imageNamed:#"theImageYouMade.png"] forState:UIControlStateHighlighted];
You can't use "setImage:" in my method because the highlighted state of the button will actually just display the 1px by 1px image in the center of the button.
My method works for variable sized buttons. Using setImage: requires you to make images that are exactly the same size as your button.
-Chris
You can try to use another image to do the job. You can also refer to this link:
Is it even possible to change a UIButtons background color?
Maybe set a different background image for a different state?
Provide a background image for UIControlStateHighlighted. Also it might help to turn off adjustsImageWhenHighlighted, though this should not matter if you're providing a separate background image for the highlighted state.

how can i make a button such that user only see the text on it but not the button iphone sdk

how can i make a button such that user only see the text on it but not the button in iphone sdk ?
i tried to lower its alpha value but even then it appears a little
If you just don't want to see the rounded rectangle of the button then set the button type to custom.
You can follow this workaround by using a UILabel instead of a UIButton. This does not answer directly to your question, as setting a custom type should and since it does not can you post some code?
Create your button of type UIButtonTypeCustom and add:
[myButton setBackgroundColor: [UIColor clearColor]];
You must use a custom button......
UIButton *custBtn = [UIButton buttonWithType:UIButtonTypeCusttom];
[custBtn setText:#"Sarabjit" forState:UIControlStateNormal];
[self.view addSubView:custBtn];