How to add a frame to UIButton - iphone

I have an app that I a writing that have 3 buttons with a background image for each button.
When the user touch one of the buttons I want that a green frame will appear around the the button for a 2 seconds and then disappear.
I know the I can build 2 separate images with and without the frame around the image but this will cause double the amount of files.
Is there any other way to do it?

Yes, you can add a border to any UIView (UIButton is a subclass of UIView) by accessing properties of the CALayer in the view:
button.layer.cornerRadius = 6; // if you want rounded corners
button.layer.borderWidth = 2;
button.layer.borderColor = [UIColor greenColor].CGColor;
You will need to import QuartzCore.h in the file to be able to reference the layer declarations:
#import <QuartzCore/QuartzCore.h>
You can turn on the border in response to the button's touch down (or up) event and then turn it off (borderWidth=0) with a timer.

i don't think there is a way to make it the way you want.
you have to make just two image, one when the button is not selected and the other when it's selected.

Related

iPhone: how to make a expandable button (like popup)

I want to make a button which while expand after clicking, and expand to contain my table-view in it. Like quick graph application
In this application it expands with animation
Either you have to create the button using a core graphics OR simply use two images for the button states.
What you can do is on the UIButton click reveal the UITableView in animation. Plus change the UIButton image to the down arrow image. This can be done simply. Also according to the image you have shown, do you really need a tableview ? I think you can make a UIView and put a UILabel in it also. Just think about it . Any further queries or code help needed kindly reply :)
For adding the border use
Table.layer.borderWidth = 10;
Table.layer.borderColor = [[UIColor grayColor]CGColor];
Button.layer.borderWidth = 10;
Button.layer.borderColor = [[UIColor grayColor]CGColor];

Adding Background Image to FlowCover

I'm using FlowCover in an app and need to add a background, but inserting a UIImageView and sending to the back in .xib only gives me the background image and buttons and no coverflow animation. I also cannot see where i would programme a
self.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:#"bground.png"]];
type thing in the implemetation.
Any clues?
It does appear that you can add an UIImageview to the ViewController's View in the MainWindow.nib:
In the editor dropdown you can send the image to the back. It means that the Flow Cover View MUST NOT be set to Opaque and then will sit on top of the ImageView.

how to Change a Rounded Rect UIbutton background color

how to Change UIbutton background color??
I try it on IB, but it doesn't work. only changes it for custom button.
I would like to change the white color on the rounded rect button.
Or instead how to make a custom button whit rounded corners
thanks!
Rounded rect button's color can be changed to any color with the background color property in IB as well as through coding, but can not change its color to transparent color easily. For that, you better use a custom button with either rounded image or set layer as demonstrated in the example and don't forget to add Quartz Core framework in you project as well as to import it in your class.
UIBUtton *myBtn = [UIButton buttonWithType:UIbuttonTypeCustom];
myBtn.frame = frame; //your desired size
myBtn.clipsToBounds = YES;
myBtn.layer.cornerRadius = 5.0f;
[self.view addSubView:myBtn];
You may find it difficult to adjust the default button. However you can use any view you want with a custom button.
Here's an article on creating views with rounded corners:
http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html
You also may look at a program called Opacity, which allows you to create a a lot of customized standard iOS interface art/buttons.
http://likethought.com/opacity/
UIButton *tagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
and have a look at this... that my do the trick.. i did it for mine.
You can use a custom UIButton with custom images for backgroundimage for each state. Just make the different states of your rounded button in photoshop for example.
You can use Custom button But for that use the image of button of white rounded corners
so it will be look like white round rectangle button
You should use UIButtonTypeCustom, instead of any other.

UITableViewCell - How to set selection clipping?

In my app, I have a UITableView and each UITableViewCell utilizes a custom background and style with the following code in the "WillDisplayCell" method:
UIImage *cellBackgroundImage = [UIImage imageNamed:#"TableView_Cell_Background_iPhone"];
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:cellBackgroundImage highlightedImage:cellBackgroundImage];
[cell setBackgroundView:backgroundImage];
[backgroundImage release];
The problem is that the PNG I'm using as the background is a rectangle, but the UITableViewCell is a rounded rectangle with a specific layer radius property. When I select a cell, the background overrides the rounded nature of the cell and I get a jarring blue highlighted sharp rectangle. Is there a way to set the selected state corner radius or something along those lines? My only other option if not would be to create a PNG background that fits the rounded rectangle perfectly.
Thanks.
I would set the selectionStyle of the cell to UITableViewCellSelectionStyleNone, this stops the blue highlight. Then start to do a custom selection job.
You will have to make a custom subclass of UITalbeViewCell. Override setSelected or if that doesn't work user a gesture recognizer or override touchesBegan etc. I have done it once, before, I forget exactly how, if you have trouble let me know and ill look it up.
When you detect that the cell is selected, perhaps create a translucent overlay as a PNG and make it appear when the cell is selected. Alternatively lower the transparency of the background image or add a color mask.

Getting a border around a UITableView, like a UIActionSheet

The UIActionSheet, when it has lots of items, is presented as a table with a border around it.
I'm trying to get a similar effect because I have a UIView with multiple UITableViews and I'd like to visually separate them. I'd like to use a border graphic that I specify.
Notice that with the UIActionSheet, the table actually sits inside the border and you see the table scroll underneath the rounded corners. You can see this in the Photos app if you view an image in landscape mode and hit the bottom-left hand corner button.
How do I get this same effect?
Edit: the "On This Day" by Sophiestication Software does something similar to what I want. The app uses a custom graphic that sits on top of a scrolling view so that the scrolling content appears to be underneath the image.
The simplest way is probably to add a border on the CALayer of the UITableView:
CALayer *layer = tableview.layer;
layer.borderWidth = 2;
layer.borderColor = [[UIColor redColor] CGColor];
layer.cornerRadius = 10;
layer.masksToBounds = YES;
Note that you need to include <QuartzCore/QuartzCore.h> and link with the QuartzCore framework.
layer.borderSize did not work for me layer.borderWidth did the trick.