Changing background colour within a TextField in Interface Builder - iphone

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];

Related

Making font colour negative to the background. iOS

I want to make text in a UILabel appear of a color negative to that background it is placed on.
I am placing the label on a web view, and I want that label to be always of a negative colour to the background so that no matter what colour (when web view is scrolled) is exactly below the text, it is always visible in a negative colour.
Thank you.
I don't recommend you to do that because the scrolling part of the webView won't be smooth with all those calculations in it. So I suggest you to set a background ImageView to your label and set a image with a negative color to your font color to that ImageView
An alternative would be setting the shadowColor to the opposite of the textColor (for example, white and black, respectively), ensuring that you'll always be able to pick out the text regardless of the web view's background color.
Don't forget to set the shadowOffset too!

Double border to a UIButton

I have to display a UIButton like in the following image. Button size can be varying. How can I do that? Please suggest a way.
If you just want a simple outline (it's a little hard to tell from your image what the button is), create the button with UIButtonTypeCustom (so you get a blank slate) then set its background color to be black. next, get the CALayer of the button (through the layer method) and set the borderColor and borderWidth properties as desired.
make a view and set it's color a bit darker than your desired button color, then make a button a bit shorter than the view size and place it as your fit position, check n tell me if it helps youe

How to create a gray overlay for a UIButton in touched state programmatically?

I would like to make a generic class that when tapped, makes the element grayish.
Facebook's app is the perfect example of what I want to achieve. All their links and images become gray when tapped.
I can only guess that they are subclassing UIButton.
I have made my button's style UIButtonTypeCustom to get rid of the rounded border. Beyond this, I don't know how to have the gray overlay because I see no such property in the documentation.
Its simple:
#define TAG_GRAYVIEW 5671263 // some random number
// add the gray overlay
UIView *grayView = [[UIView alloc] initWithFrame:button.bounds];
grayView.backgroundColor = [UIColor grayColor];
grayView.tag = TAG_GRAYVIEW;
[button addSubview:grayView];
// remove the gray overlay
UIView *grayView = [button viewWithTag:TAG_GRAYVIEW];
[grayView removeFromSuperview];
I think you need to use a semi transperant grey image PNG file. You need to then set Image of button in Highlighted state.
Also note that both the images for Normal State and Highlighted State need to have the images with titles on them.
As once we set the image to button, btn.titleLabel.text won't be displayed.
So you can have a image with transperant background and title on it for Normal state. And an grey image with title on it for Highlighted State.
Code for doing it programmatically is
[btn setImage:#"Transperant.png" forState:UIControlStateNormal];
[btn setImage:#"Grey.png" forState:UIControlStateHighlighted];
Hope this helps you.
The default UIButton masks the opaque content using a gray highlight. For example when using a transparent png, only the parts that contain non-transparent pixels will be grayed out on touch. The default UIButton highlight has no effect on subviews/sublayers, and will only work on provided images. What you see in the Facebook app is probably just a UIWebView highlight, possibly customized using css.
To create something similar using your own control (to prevent the overhead of a UIWebView) you should probably create your own UIControl subclass and highlight the content on touch using a transparent CALayer. You can even mask the CALayer to only highlight the actual contents, instead of a rectangular shape.
Also see my stackoverflow post on creating custom controls for iOS by subclassing UIControl.
Try setting the button up something like this.
*mind you I didn't create the image for this example.
Set your button type to custom, and in "State Config" select "Highlighted" from there you will want to set the image of the button to be a semi-transparent grey image. There are probably several other ways to achieve this same effect but this one should be nice and simple.

Tinting the background pinstripes of a grouped UITableView

How do I apply a tint to the background of a UITableView using the grouped style? The standard "color" used ([UIColor groupTableViewBackgroundColor]) is tinted blue; I want a green tint instead.
This uses a pattern rather than a true color. I just want to tint that pattern to match the colors I'm using elsewhere, not replace it with a solid color.
The easiest way is to make a screenshot of the default grouped tableview background and crop it so that its size is 7x1 pixels (that's enough to tile it). Adjust the tint color (hue, saturation, brightness) in your favorite image editor and use the resulting image as a pattern color via +colorWithPatternImage:, e.g.:
myTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"GreenStripes.png"]];
You could probably do this somehow with coregraphics by drawing the grouped tableview color to a context, tinting it, and then using a bitmap of the context as a repeated background for your tableview somehow. I couldn't tell you just how to do that, though.
Why not just do the tinting in Photoshop or GIMP or something and save it as a 32x480 (or whatever res you need) image, and use that image as your tableview's background image. To get the initial pinstripe image, just make a fullscreen view with that as the background color.
A third option would be to place a translucent green view above another view with the grouped tableview background color. Don't know how well that would work, though.

Black corners on UITableView Group Style

I have a problem where my UITableView (group style) has a black "tip" above it's rounded corner.
I'm setting up the background of the tableview like so:
[meetingTableView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:#"background.png"]]];
And my table view ends up looking like this:
black pointy edge on rounded corner http://papernapkin.org/pastebin/resource/images/imageEntryId/6487
Any ideas how I can get rid of those black points?
I have got the same problem.
When I set clear color by xib, I have the back corner
The solution is to set it by code !
(The same problem with interface builder exist for webviews)
Try this in your controller's viewDidLoad method:
meetingTableView.backgroundColor = [UIColor clearColor];
You'll get Black corners on UITableView Group Style if you set background color to clear color in XIB.
Instead try this code for removing Black corners on UITableView Group Style
tableViewObject.backgroundColor=[UIColor clearColor];
Just in case you weren't already aware, there's another neat technique you can use to make customized backgrounds for UITableViews:
Not quite as simple as setting the background as you're doing, but it gives you a lot more flexibility and can scale to any table size.
Maybe if you put yourTableViewOutlet.backgroundView=nil;
To avoid the black corners you have to make sure that the UITableViewCells are not opaque. It looks like you're using custom styles table cells and the default value for opaque is YES. Either go to Interface Builder and uncheck the opaque checkbox if the table cell was set up in a XIB file. Or use the setOpaque:NO setter to change value.
Because the table cell view still has a rectangular frame even with the rounded corners the cell view and not the actual table view is causing those black corners.
My guess is that it's related to something that you're doing in your custom table view cells. You might want to experiment with setting the cell background color to [UIColor clearColor].
I think you should set the background color of your table as clearColor and initialsie your view with the background image.
Then it will definitely not show the black corners. But also don't forget to set the background color of your cell as white color
The up-voted answer above (set the tableView's background to [UIColor clearColor]) may not work for you if you are like me and never use the UITableViewController, instead putting a UITableView inside a UIViewController.
In this case it's not the tableView that needs to have a clear background, but the view that holds the tableview.
This is not intuitive, but it works for me. In interface builder you can just set the parent view's background color to clear color, or you could do the same in code in viewDidLoad with:
self.view.backgroundColor = [UIColor clearColor];
I'm guessing the reason for the black corners is something about the internal graphics optimization, and setting the background clear fixes it.