Outline text/font in UIButton - iphone

I'm working on a project where UIButtons can have their font color dynamically set depending on user settings. To avoid the issue of a light font on a light background or a dark font on a dark background I'd like to outline my font with a thin, black outline. I'm talking about an outline directly around the letters, not around the label or button itself. Something like the typical LOLcat Impact font outline: http://mintyferret.com/wp-content/uploads/2007/07/lolcat7.gif
Does anyone have an example of this in action? I'm open to suggestions if you have something easier, but I'm not really in a place where I want to create custom images for my buttons. They can have dynamic text and dynamic colors, so I need it to be pretty flexible.

UIButton contains its title in a UILabel and UILabel has no option to add borders around your characters. The titleLabel property of UIButton is read-only, so you can't replace it with your own UILabel subclass. Therefore, the only option appears to be to draw the text in the button's drawRect function.
Here's a topic on how to draw borders around text:
How do I make UILabel display outlined text?
I'm pretty sure you'll have to override the setTitle:forState: and currentTitle functions using your own variables, or the button will draw text behind or in front of the text you draw.

Related

Make bottom part of UITextField(UIScrollView) transparent

Here's a good example that sums it up:
This is a UITextField that contains long text, so the user is able to scroll down to view the rest of the text.
How can I make the bottom rows appear "transparent"?
UITextField only allows setting global text properties (like color, font size, etc).
The trick is to create a CALayer containing a gradient and use it as mask layer of your UIView's layer (alpha values of the mask layer will be used.) see this answer: UIView border with fade or blur effect
This will help you.Not sure but some functionality like you want.
Hope this helps you.
All the best !!!

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.

What's this UI element?

What's the UI element that is top of that number buttons to display number ? (which is in light blue color)
It looks like a UINavigationBar with a prompt. However, the location of the gloss (which differs from your typical UINavigationBar) and the centering of the numbers (not shown) makes me think it is a custom view.
If you're trying to replicate it, I'd suggest starting with a UIView. Add a UIImageView with appropriate image for the the blue background and a UILabel for the text. Or, instead of the UIImageView, you could draw the background in the UIView's drawRect: method.

UIButton - unwanted background well

I'm creating UIButtons (type = UIButtonTypeCustom) with a custom background drawn by an artist; unfortunately UIButton is adding an unwanted 'well' effect around the backgroundImage (as specified via setBackgroundImage). Is there a way to disable the well? It's not a simple drop shadow, so messing with the CALayer properties doesn't seem to help. I realise I could use UIControl, but that's considerably more work, since I need to handle the label subview myself, and get the artist to produce highlighted versions of the artwork - UIButton is doing all that nicely, if I could only disable the well effect.
Put your image inside a UIImageView, and then position your UIButton on top of it. Use the "custom" style, which has no UI to it at all and is totally invisible.
If you want to change ("highlight") your button image when the button is hit, just change the image contained in the UIImageView in whatever method your UIButton targets.