How to add a "play" icon on top of UITableviewCell imageView? - iphone

I have a tableview witch display video thumbnails. I would like to add/overlay a "play" icon on top of the thumbnails.
How to add this icon on all my thumbnails?

Add a custom button over your video thumbnail image with a transparent play png. Doing this will also allow you to hook that custom play button up to an action that could allow the user to play the video.

Here's what I do for my app:
UIImage *play = [UIImage imageNamed:#"play1.png"];
self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.playButton setImage:play forState:UIControlStateNormal];
[self.playButton addTarget:self
action:#selector(playVideo)
forControlEvents:UIControlEventTouchUpInside];
Something that drove me nuts: Be sure to use a png NOT named "play.png"!

Agree withWrightsCS. You may want to seal your thumbnail into a separate class (let's say, a new subclass of UIView). And you customize it and put an transparent play icon on top of it.
Then you go back to you tableview's cell's class, and hook up that new thumbnail class with an action you want it to trigger.

Related

iOS using image background for Button

i have that image background with transparent part and i went using for my buttons without
transparent part and if possible with interface builder
By the sounds of it you are possibly using the UIButtonTypeRoundedRect style, but UIButtonTypeCustom may be more suitable. You can change this within Interface Builder's inspector window.
still i refer this link http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12
btnImage = [UIImage imageNamed:#"image.png"];
[btn setBackgroundImage:btnImage forState:UIControlStateNormal];
[btn setTitle:#"Title" forState:UIControlStateNormal];
or you can directly set background image from your xib by changing it into custom type.

IOS Custom UIButton

I currently work on a small application in which I have several UIButtons. Each of them has an UIImageView beneath it. At the moment, I associate each UIButton with each UIImageView (all are named via an IBOutlet - UIButton and UIImageView). When I press a button, the underlying image changes. I would like to know if it's possible (and how) to create a button which contains an underlying UIImage (not a UIButton image or background image), a sort of new object.
This image is slightly larger than the associated UIButton, like the apple calculator basic apps, and this image changes when I press the button.
I've tried several solutions (certainly incomplete) and I'm beginning to despair.
My current solution is functional but I do find it not particularly elegant.
UIButton has both image and backgroundImage as its properties.
To achieve what you are looking for, I would actually recommend you to stick to just a UIButton, and then using contentInset to position the image over the backgroundImage so it creates the effect I think you are looking for. This should be quite easy in interface builder...
you can make an invisible button and behind it make the image..
This will give you what you want but should be avoided at cost...
Stick to UIButton..
I believe even in calculator app they are only UIButtons and nothing else..
they have been coded to been momentary selected ..so that's why you see them kind of changing highlight for a small fraction and each button have been coded to perform specific function(+ - / equal .)
Update : i might be in doubt but if you asked for a button to have an image view inside it..
then here is the answer.
Make UIbutton. Make an ImageView and then call [theButton.view addSubview:ImageView];
Since both UIbutton and UIImage view inherit from UIView.. you can add as many subviews to them..that is inside them
If I understood your question correct then you may try the following:
UIButton *button = [UIButton alloc]init];
[button setImage:buttonImage forState:UIControlStateNormal]; when button not pressed
[button setImage:buttonImage forState:UIControlStateSelected]; when button tapped
[button release];

limiting the touchable area in a UIButton in IPhone?

I have three custom buttons with non-rectangular images close to each other in my view. Then I have a problem with touchable area's of each button overlap with other buttons. So how can I limit the touchable area of each buttons to get the corresponding actions?
You can overwrite -pointInside:withEvent:, that internally will be used for hit testing.
A nice project using this technique is OBShapedButton, where transparent pixel will not trigger a hit.
Use two components. A UIImageView with a smaller UIButton on top.
You should create custom Type Buttons and add required images on each using this code:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:#"image.png"] forState:UIControlStateNormal];
[btn setFrame:frame];
Creating buttons with images this way will not result in overlapping images issues !!

how to show active button in iphone app

I am developing an application in which there are 7 buttons in every view.
We can switch on any view with respective to button clicked.
Now I want to enable(by change color or background or any thing) the clicked button, means all buttons should remain as it is only the clicked button should look different.
you can use
[button setImage: forState:];
This will help if u are using images for the button
[button setBackgroundImage: forState:];
You have two images like "selectedImg.png" and "unselectedImg.png" and change them according to the selection.To change the image use the following setter method,
[selectedButton setBackgroundImage:selectedImg.png forState:(UIControlState)state]
In the case of "setImage:" the image size will not resized for your button size.But in "setBackgroundImage:" will resize and set that as background.

Standard UIButton with custom image

I'm trying to add a custom image on a standard UIButton. I know of the setBackgroundImage and setImage methods to do that. However, this will remove the 'standard' borders! Using UIButtonTypeCustom or UIButtonTypeRoundRect gives the same results...
Can this be so hard?
A normal button like those in the navigationbar - just a custom image instead of the titleLabel. Do I really have to draw the button itself in an image editor?
Yes you do have to draw a custom image.
Well you can add a subview of image to the UIButtonRoundRect. So just create a RoundRect button the usual way:
UIButton *button = [UIButton buttonWithType:UIButtonRoundRect];
then create an image view with your image and add it as subview to the button:
UIImageView *iv = [[UIImageView alloc] initWithImage:(UIImage *)image];
[button addSubivew:iv];
That should do the trick. Plus you can also set the position of that imageview by [iv setCenter:CGPointMake(x,y)];
Hope that helps.