This picture shows what i want , i just making a custom movieplay controller.
alt text http://www.imagechicken.com/uploads/1279252703012036800.png
I know how to make a custom uislider as code below
playSlider.backgroundColor=[UIColor clearColor];
[playSlider setThumbImage:[UIImage imageNamed:#"sliderButton.png"] forState:UIControlStateNormal];
[playSlider setMaximumTrackImage:[UIImage imageNamed:#"sliderGray.png"] forState:UIControlStateNormal];
[playSlider setMinimumTrackImage:[UIImage imageNamed:#"sliderBlue.png"] forState:UIControlStateNormal];
but that can not help me .Is there any ideas? Thank you for any advices!
I think you could get away with a UISlider only if the thumb was never allowed to leave the blue (loaded) area. Then you could draw the inactive (unloaded) track to the right of the actual slider bounds, and just update the bounds for the slider as the video loads, which would increase the blue area. But you'd still have to do the right math for the slider thumb's relative progress.
If you need the thumb to swipe into the unloaded area, or you want to avoid a headache with the recalculation, you should just build your own control. Unfortunately, the UISlider is not a highly customizable control by itself.
You should be able to subclass drawRect on the UISlider to customize that, but I may be wrong.
overriding drawRect: is not a good idea.
You will have to make a custom object containing something like:
an UIButton for the play/pause, an UISlider for the slider, an UIButtons for the mute on/off,
and a UIView for the volume (you will have to implement by your self)
Actually is not difficult, is just an container object.
Related
I have a subview layering problem where I have a rotating arrow and a UIButton. The arrows rotate and the UIButton changes depending on the rotation of the arrows. The problem is that I need to have the UIButton clickable. At the moment the arrows rotate but the UIButton is not touchable. If I try [self.view sendSubviewToBack:wheelControl]; the arrows are sent to the back and are no longer visible.
thanks for any help about how I might fix this.
You need to call
[theView bringSubviewToFront:theButton];
as the last call when laying out your subviews.
As a part of my app i need to fire a method while clicking any where inside a human hand image. Human hand image is placed in a image view. i need to add a button in-spite of adding gestures. Is it possible to create a custom button like human hand exactly show in the image below?
thanks
Create a custom UIButton add the image hand as its backgroundImage or setImage. Then use /assign this image inside. Like below:
handButton = [UIButton buttonWithType:UIButtonTypeCustom];
[handButton addTarget:self action:#selector(handImage_touch) forControlEvents:UIControlEventTouchUpInside];
[handButton setBackgroundImage:[UIImage imageNamed:#"handIMAGE.png"] forState:UIControlStateNormal];
handButton.frame = CGRectMake(x, y, width, height);
[self.view addSubview:handButton];
-(void)handImage_touch{
// do anything
}
I think at first you have to make polygon which fit to your image. And then you can use touchesBegan:withEvent: to get the coordinate of touch point and judge whether the point is inside of polygon or not.
Here is similar question like yours.
How to get particular touch Area?
I think this is a little difficult work, so maybe you would better use cocos2d library which have collision judgement function.
http://box2d.org/forum/viewtopic.php?f=9&t=7487
But also I think iOS is well constructed for handling touch, so this is beneficial effort for you.
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.
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];
I know how to build a round UIButton by using the cornerRadius of the CALayer of a UIButton.
col1 = [UIButton buttonWithType:UIButtonTypeCustom];
col1.layer.cornerRadius=w/2;
col1.layer.masksToBounds=YES;
Is there a way to do more interesting things about the boundary like chop off half a corner with CALayer?
Any examples?
I'm not sure what you mean by chop off half a corner, but the only other interesting thing you can really do to change the shape of a button using CALayer is setting the mask property. Be careful, though, as this is a fairly significant performance hit, plus it won't affect the touch behavior of the button at all, only the visual.
In general, you should be setting custom background images for your buttons if you want to change how they look.