How To Make A UIButton Match My NavBar? - iphone

I have a custom color navbar using the following code:
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:35/255.0 green:161.0/255.0 blue:202.0/255.0 alpha:1.0];
I want to make a UIButton with the exact same color and gradient that the navbar is. I've tried in photoshop but don't know how to make the 2 tone graident style.
Is there anyway to do this programatically? I already have the buttons set up in IB.

Check out this link. There you can find a class that extends UIButton, so that you can change the color of your buttons and even do some gradient.

Related

Change UIToolbar Shadow Color For UIBarButtonItem

I am styling a UIToolbar by changing the tint color of it and the tint color of its UIBarButtonItem subviews. I have it working except that I can't find how to change the the shadow color from a dark color to a light color for the individual bar button items (see example, bar button items look blurry):
How can I change the shadow on the UIBarButtonItem with style UIBarButtonItemStylePlain to be white? I've uploaded a sample project here.
The final solution was to add the buttons as UIButton contained in UIBarButtonItem and include any shadows in the PNG used for the UIButton image.
In the UIBarButtonItem Class Reference there isn't a single mention of the word "shadow"
You use an image for the shadow, not a UIColor
Some source code examples can be found # cocoaControls.com
For the UIBarButtonItem appearance only the 2 images and colors can be changed:
setBackgroundImage:forState:barMetrics:
Sets the background image for a given state and bar metrics.
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics
For the UIToolBar:
For adding your own custom shadow look at this StackOverflow
post
For using cocoa-predefined functions look at UIToolBar Class
Reference
setShadowImage:forToolbarPosition:
Sets the image to use for the toolbar shadow in a given position.
(void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom
shadowImageForToolbarPosition:
Returns the image to use for the toolbar shadow in a given position.
(UIImage *)shadowImageForToolbarPosition:(UIToolbarPosition)topOrBottom
I don't know what else to say, there isn't a shadow method for the UIBarButtonItem.
I hope this is self explanatory.

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.

Changing background colour within a TextField in Interface Builder

I want to be able to set the color inside a Text Field to be a different color than the default white.
I can make it grey by reducing the Alpha value but i want to use colors other than gray to denote certain conditions. i.e. red for a warning.
I hate asking such a simple question but I did some Google Searches and don't see anything to give me some insight.
I want to use colors, not an image as that would be more efficient than using images. But if it only works with images then guidance on that would be great.
I know there is a Background image you can set but that is more to make the border a different color. I want the color inside the text field area to be a different color.
If there is a way to do this in code but not in IB, that would be useful for me as well.
Thanks,
Dano
To change the background color in IB, set the Border to other than round rect.
Programmatically:
UITextField *myTextField;
myTextField.borderStyle = UITextBorderStyleNone;
myTextField.backgroundColor = [UIColor redColor];
You can change the background color within the Text Field attributes under the "view" tab in Interface Builder.
Note that the setting for "Background" setting for changing the background color is well hidden at the bottom of all the settings, unlike the "Background" setting for setting a background image, which is right at the top of the screen.
to set the background of the textField:
UITextField *myTextField;
myTextField.backgroundColor = [UIColor redColor];

change UIbutton color inside UITableViewCell

I have a simple problem ... but its turning into a very difficult problem .. i have a button inside uitableviewcell and want to change its color through code .... i could aceive it by changing its background image. But its kinna hazy ... its not the solid color ... and when i use [cell.button setBackgroundColor:[UIcolor redColor]] ... the button color does not change ...
any help appreciated
thanks
I am not sure about how are you doing this, but if it is possible, why don't you keep reference to this button.
You can initialize it, insert it on your table and all the time that you need to change something, you use the variable that you have initialized.
// On your .h
UIButton *myButton;
// On your .m
// Initialize it.
// when displaying cells
cell.button = myButton;
// when you need to change the color use your myButton reference
myButton.backgroundColor = ......
Cheers,
VFN
If you have a background image (correct me if I got it wrong) then there is no chance to change the background color (or, at least, see this change) without changing the background image...
If you don't have a BG image then it should work...
Where do you change the color?
Inside the tableView:cellForRowAtIndexPath: or do you have a reference to the button?
UPDATE:
Haven't noticed the [cell.button.
What is cell?
Actually changing the background color would change the corners of the button slightly but you may not notice it as rounded rect button just blocks its background as long as it is not transparent.
I believe what you want to do is to change the tint color.
try
[cell.button setTintColor:[UIcolor redColor]];
I guess it should work.

iPhone UISegmentedControl button states on black UIToolbar

I have a UISegmentedControl on a black UIToolbar. I have set the style to Bar and set the background color to clear (also tried black). I have tried setting the tintColor clear (also tried black). My buttons turn black to match the black UIToolbar. However, the buttons no longer indicate a clicked state like they do when the UISegmentedControl is the default blue/grey. What do I have to do to make the buttons indicate a black/grey clicked state? Please let me know. Code used so far to set the color of the UISegmentedControl:
viewTypeSelection.segmentedControlStyle = UISegmentedControlStyleBar;
viewTypeSelection.backgroundColor = [UIColor clearColor];
While not a perfect solution, this works pretty well
// set the color
viewTypeSelection.segmentedControlStyle = UISegmentedControlStyleBar;
viewTypeSelection.tintColor = [UIColor darkGrayColor];
The buttons have state change and it looks OK. Here is a post that has a few more details and might help someone looking for a similar solution:
UISegmentedControl black?
You may have set the color of the bar with tintColor instead of setting barStyle like so:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;