UIbutton highlight part of the image - ios

I want to have a UIButton that has an image as the button itself, to have a nice highlight when pressed but not on the entire rectangle but on the object in the image (quite similar to what Twitter is doing on the status bar buttons)
I thought that making an image with the background as transparent will solve the problem, the thing is that on one it works, and on one it doesn't and they are exactly the same property wise.
So my general question:
What are the steps I need to do in order to get this done?

Related

iOS Add Image to TextField

I am experimenting a little bit witch apps programming.
How I can add a UIImage to a UITextField"?
Like Whats App or the most other Chat Apps.
I have search some time but doesn't find a solution, also i have tried to search in side of XCode with the auto complete but I have not found a function. So I hope you can help me.
The easiest way to add an image to a text field is to have a UIView that contains both UITextField and a UIImageView as subviews.
Next up, you can have a UIButton with both an image and text, and just set userInteractionEnabled to "NO" and it'll behave like a text view with an image next to it.
Now to get more complicated, if you want a chat-like text field that allows text (that you can type into) and images next to each other, you need to start thinking about custom subclasses. Other people have asked and have gotten answers for this same approach.

iOS Tab Bar questions (Swift)

I have a couple questions about the iOS tab bar.
My first question is, is the image always tinted automatically? Say for example, I used an image that was colored red, is there a way to get it to show the red without tinting it? I guess what I am saying is, can you show the natural color?
My second question is, assuming the tinting is mandatory, how would I go about tinting the images in the tab bar that are not the currently selected image? I have the selected image tint figured out.
I tried changing the tint under, UIView.appearance() I believe and that worked, but when I selected a different tab, and then navigated back the color went back to the former grayish color.
If I am not being clear enough, let me know and I will explain more. I am using swift, so any examples you give would be great in swift! Thanks!
Say for example, I used an image that was colored red, is there a way to get it to show the red without tinting it?
What you want to do is to specify an image with rendering mode .AlwaysOriginal.
To govern both images, create the item with initWithTitle:image:selectedImage: and make them both .AlwaysOriginal.
(As you discovered, if you use a transparency mask and rely on the tintColor, you lose control of the tint color when unselected.)

What exactly IS the highlighted image in a UIImageView?

This question boggles my mind and I cannot find an answer. I looked all over the documentation, tried out code, and searched Google, but I can't find anything. The UIImageView in iOS programming can have an image set to it, but you can also set a highlighted image to it. What exactly is this highlighted image?
you can set two different images to an UIImageView, one to its image property, another to its highlightedImage property.
There are many cases where you want to change the state of the image (eg: a checkmark) from off to on or vice versa. in that case, instead of you setting the UIImageView's image to the appropriate one everytime, you can just say
theCheckMarkImageView.image = regularImage;//set the regular image
theCheckMarkImageView.highLightedImage = highlightedImage;
(based on your logic show it highlighted or not).
theCheckMarkImageView.highlighted = YES/NO;
In addition to all this, do check Ethan Huang's answer about how tabelviewcell works with this property. Quite useful if you are showing different images based on cell selection.
highlightedImage use for highlight ImageView,simple.
imageView.highlightedImage = [UIImage imageNamed:#"hightlighted.png"];
imageView.highlighted = YES;
Don't need to waste time to search or read a lot. Objective-C is meaningful language. Just drag ImageView and make a try code, step by step test all property, method in UIImageView.h(in UIKit framework) and you'll understand.
Do the same with other UI element.
Besides Nitin Alabur's answer, a useful tip here:
UITableViewCell or UICollectionViewCell has a .selected property. If you put an UIImageView in a cell, then, when you select the cell, the imageView will use the .highlightedImage instead of .image.
Thus you can make cell selection visual state easily.
The highlighted image is for when you have a control that has a UIImageView that can be pressed. While the user is pressing the control, the highlighted image is shown. When the control is not being pressed, the normal image is shown.
All commenters have been wrong or answered the wrong question or been too wordy. Here's the simple and correct answer:
The highlighted image state is when the user's finger is touching the imageview.

Changing look when tapping button with layer gradient

I used this question:
How to create a UIButton with a black gradient for iPhone?
... to set up a color gradient as the background of my button and it looks great, but when I tap the button it doesn't visibly change and give the user any feedback that they successfully tapped the button.
How can I set up a second gradient for the highlighted state or something like that?
Well, you are setting a sublayer and not providing any content to the button's views. The sublayers are drawn directly, so the UIButton doesn't think it has any content to "highlight". If you want a different effect on your button when you select it, there are three simple approaches.
One is to make two images with gradients. A pressed and normal state. This is much simpler as you can design them as you want and its a simple one line, one time implementation.
The other option is adding selectors that get called when your button gets UIControlEventTouchDown and whichever other Control Event(s) you want to have it switch back under.
The last simple option is to subclass UIButton and use the UIResponder touch methods to determine when to manually switch between the different background types.

iOS: Back toolbar bar button item

I need the back arrow toolbar bar button item.
In identifier of bar button item, there is play, refresh, reload, and stop.
I need the image of play, but flipped 180 degrees.
Is there a way to flip the image with code? If not, where can I find this image?
here's a simple work around:
declare your button with "initWithTitle" and set the title to #"◀" (it's just a unicode symbol).
Use #"▶" for the forward button to make it consistent.
I tried it and it worked for me.
Do a Google search for play button vector graphic. Make the one you want the image of the button. Should still be able to tell the button to maintain it's bar button style.
One straightforward option is to draw a white triangle of the appropriate size and orientation in an image editor, stick it in an image view, and then use that image view for a bar button item's custom view.
I wouldn't try to use the UIBarButtonSystemItemPlay image. I don't know if manipulating system images is expressly proscribed, but Apple generally doesn't smile on misuse of system items. When you get right down to it, it's just a white triangle, so it'd be hard to tell the difference between drawing your own or reversing theirs. That just seems like all the more reason to draw your own.

Resources