In my app,I am playing video using MPMoviePlayer.
I am adding a "Skip Ad" (you can see that on the right side of movie player)button on Movie Player.It works fine in iOS5, but when I run my app in iOS6, the button is hidden when Movieplayer becomes fullscreen.
Why this happens..any idea ?
Help me to overcome this..thanks in advance
Here are the code for adding button on MPMovieplayer,and the screen shots
UIButton *skipButton = [UIButton buttonWithType:UIButtonTypeCustom];
skipButton.frame = CGRectMake(264.0,195.0, 67.0, 25.0);
[skipButton setTitle:#"" forState:UIControlStateNormal];
skipButton.backgroundColor = [UIColor clearColor];
[skipButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal3 = [UIImage imageNamed:#"skipad.png"];
UIImage *strechableButtonImageNormal3 = [buttonImageNormal3 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[skipButton setBackgroundImage:strechableButtonImageNormal3 forState:UIControlStateNormal];
UIImage *buttonImagePressed3 = [UIImage imageNamed:#"skipad.png"];
UIImage *strechableButtonImagePressed3 = [buttonImagePressed3 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[skipButton setBackgroundImage:strechableButtonImagePressed3 forState:UIControlStateHighlighted];
[skipButton addTarget:self action:#selector(skipAction:) forControlEvents:UIControlEventTouchUpInside];
[[[UIApplication sharedApplication] keyWindow] addSubview:skipButton];
in iOS5 -
in iOS6 -
bringSubviewToFront should work, just make sure you're using it correctly. The usage is:
[skipButton.superview bringSubviewToFront:skipButton];
If that doesn't work you can change the zPosition like so:
skipButton.layer.zPosition = 1024.0;
Related
NOTE: I can get this to work by switching leftbarbuttonitem to rightbarbutton item in my barbutton and barbutton2 methods. I'm just curious to know why it won't work normally!
For some strange reason, my leftbarbuttonitem is showing, but my rightbarbuttonitem just never pops up! Here's my code
-(void)barButton {
image = [UIImage imageNamed:#"BBut.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage: [image stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button setBackgroundImage: [[UIImage imageNamed: #"BBut.png"] stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
[button addTarget:self action:#selector(showlocations:) forControlEvents:UIControlEventTouchUpInside];
button.frame= CGRectMake(3.0, 0.0, image.size.width+1, image.size.height+0);
UIView *v=[[UIView alloc] initWithFrame:CGRectMake(3.0, 0.0, image.size.width+1, image.size.height) ];
[v addSubview:button];
UIBarButtonItem *modal = [[UIBarButtonItem alloc] initWithCustomView:v];
self.navigation.leftBarButtonItem = modal;
-(void)barButton2 {
image2 = [UIImage imageNamed:#"Refresh.png"];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setBackgroundImage: [image2 stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button2 setBackgroundImage: [[UIImage imageNamed: #"Refresh.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
// [button2 addTarget:self action:#selector(viewDidLoad) forControlEvents:UIControlEventTouchUpInside];
button2.frame= CGRectMake(281.0, 5.0, image2.size.width, image2.size.height);
UIView *v2=[[UIView alloc] initWithFrame:CGRectMake(281.0, 5.0, image2.size.width, image2.size.height) ];
[v2 addSubview:button2];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithCustomView:v2]; self.navigation.rightBarButtonItem = refresh;
NSLog(#"THE ACTION HAS BEEN RECIEVED!"); }
In my ViewDidLoad Method, I have this:
[self barButton2];
[self barButton];
The action does go through and I do receive my NSLog method. Does anyone know why this is happening? The Left Bar Button always shows up and if I change the the first barbutton to rightbarbuttonitem and change the barbutton2 to leftbarbutton item, and then change the CGRect coords, it works, and that's what I'm using right now to get it to work, but why is this happening? Thanks in advance.
You don't see the right button because you are drawing it outside the screen.
The button2 X coordinate is set to 281.0 and its parent view X coordinate is also set at 281.0. As a result your button is in x = 562, meaning it is outside the screen.
Set your button2 X coordinate to 0 and see if that helps:
button2.frame= CGRectMake(0.0, 5.0, image2.size.width, image2.size.height);
You seem to be creating a new view with each action and adding a button. So, you never see both buttons. You will need to access the same view in both the actions to make sure you add two button subviews.
So I create a button. I want it to have rounded corners with out making rounded .png files
I can set the background image ok. I can round the corners ok. However, when I set the background Image the rounded corners go away.
I did this once before a long time ago but can not seem to get it working again. How can this be done?
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 addTarget:self action:#selector(goSpecials)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:#"Specials" forState:UIControlStateNormal];
button1.titleLabel.font = [UIFont fontWithName:#"Arial-BoldMT" size:(15.0)];
[button1 setTitleColor:[self colorWithHexString:buttonColor] forState:UIControlStateNormal];
button1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: #"button.png"]];
//[button1 setBackgroundImage:[UIImage imageNamed:#"button.png"] forState:UIControlStateNormal];
button1.frame = CGRectMake(20.0, 232.0, 135.0, 32.0);
button1.layer.borderColor = [UIColor blackColor].CGColor;
button1.layer.borderWidth = 0.5f;
button1.layer.cornerRadius = 8.0f;
[self.view addSubview:button1];
button.png:
Add the maskToBounds property to your button.
button1.layer.masksToBounds = YES;
well, i'm making an app from a UiWebView example i found. and i needed to add a button but the way this example works is similar to phonegap so i figured out i need to add the button as a subview to the window, so then i got my button and set it up for pressing but when ever i press it my app crashes... can any one help? here is my code snippet:
- (void)webViewDidFinishLoad:(UIWebView *)webView{
myLoadingLabel.hidden = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[window addSubview:webView];
//my button
UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
playButton.frame = CGRectMake(122, 394, 76, 76);
[playButton setTitle:#"Play" forState:UIControlStateNormal];
playButton.backgroundColor = [UIColor clearColor];
[playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:#"mic.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:#"mic.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[playButton addTarget:self action:#selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
[window addSubview:playButton];
}
-(void)playAction {
NSLog(#"Button Pressed!");
}
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIWebView_ExampleAppDelegate playAction:]:
oh and i know its a long shot, but i need this button outside of the webpage because it needs to start recording audio when clicked, then when clicked again it needs to stop recording and save, run a command with system();, and then put the data gotten from the system command into the uiwebview to be used... so yea if anyone knows some code i would appreciate it greatly, and its a jailbreak app so the system command will be ok. Thanks!!!
You are invoking a method named playAction: but you implement a method named playAction. Mind the missing colon. The crash most likely is related to that issue.
For a quick fix, change
[playButton addTarget:self action:#selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
to
[playButton addTarget:self action:#selector(playAction) forControlEvents:UIControlEventTouchUpInside];
The problem is this:
#selector(playAction:)
vs.
- (void)playAction
The former refers to a method called -playAction: that takes one parameter, but you’ve implemented a method called -playAction that takes no parameters. Drop the colon from the #selector block and it should work.
I have to create my own customized slider. I am trying to change the thumb image,background of the slider and in the some test like slide to unlock.
I have tried like this but its not working
CGRect frame = CGRectMake(0.0, 219.0, 323.0, 20.0);
UISlider *myslider = [[UISlider alloc] initWithFrame:frame];
[myslider addTarget:self action:#selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[myslider setBackgroundColor:[UIColor clearColor]];
[myslider setThumbImage: [UIImage imageNamed:#"sliderThumb#2x.png"] forState:UIControlStateNormal];
myslider.minimumValue = 0.0;
myslider.maximumValue = 50.0;
myslider.continuous = YES;
myslider.value = 15.0;
[self.view addSubview:myslider];
But in this the size of thumb pic is very big.How to reduce the thumb pic size....and how to give the slider background and text.Please help me out
[[UISlider appearance] setThumbImage:[UIImage imageNamed:#"ball.png"] forState:UIControlStateNormal];
[slider setMinimumTrackImage:[[UIImage imageNamed:#"volume_slider_oragne.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal];
[slider setMaximumTrackImage:[[UIImage imageNamed:#"volume_strap_gry.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal];
To set the background colour of the slider, I would presume that you can set the property backgroundColor to [UIColor colorWithPatternImage:[UIImage imageNamed:#"slider background"]];
Also, images that have the appending ending of #2x, mean that they are twice the size of the standard copy. This is for retina displays only, you should not use it in a UIImage on a standard (legacy) device. Try setting the image name to #"sliderThumb.png" instead, as long as you have the legacy copy of the image.
Just provide a different size of sliderThumb#2x.png and all we work itself out.
How can I set the background color of a particular button in iPhone?
I used:
btnName1 = [ColorfulButton buttonWithType:UIButtonTypeRoundedRect];
btnName1.frame=CGRectMake(45,146,220,40);
[btnName1 setTitle:#"Continue" forState:UIControlStateNormal];
[btnName1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnName1 setImage:[UIImage imageNamed:#"green.png"] forState:UIControlStateNormal];
UIImage *img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:#"greenish" ofType:#"png"]];
UIImage *strechableImage = [img stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[btnName1 setBackgroundImage:strechableImage forState:UIControlStateNormal];
[btnName1 setNeedsDisplay];
[InfoView addSubview:btnName1];
It's correctly working on iPhone simulator but not on iPod (color not shown in iPod).
myButton.backgroundColor = [UIColor redColor];
Or whatever colour you want. This method is inherited from UIView.
Note that this only sets the background colour...
If you want to change the button's look:
[myButton setBackgroundImage:[UIImage imageNamed:#"MyImage.png"] forState:UIControlStateNormal];
You can change the state to whichever state you like.
EDIT: If you are adding the button from interface builder, make sure to change the button Type to Custom, and change the image.
This is how I got it done.
In the .h file declare yourButton as an IBOutlet.
#property (weak, nonatomic) IBOutlet UIButton *yourButton;
In the .m file where you want to change the colour of the button use either
[yourButton setBackgroundColor:[UIColor blueColor]];
or
[yourButton setBackgroundColor:[UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0]];
To obtain the colours I require I use this link.
i had the solution when code is written in viewdidload() it's properly work eariler i used for uiview thatswhy it's not work.