Stop UIButton turning blue when pressed - cocoa-touch

In my iPad app I have a UIButton that when pressed initiates some data transfer which takes time. During this time the button turns blue as shown:
Is there anyway of changing this colour?

Change the tint color, it will be used when button is highlighted.
[myButton setTintColor:[UIColor blackColor]];

Try This
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 50, 100, 50)];
[button setTitle:#"hi" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:button];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
button.backgroundColor = [UIColor whiteColor];
[UIView commitAnimations];

Related

UIButton changes shape when pressed

-(IBAction)actionButtonPressed:(id)sender {
//Write the code to show the buttons etc like play
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.actionBtn0 setFrame:CGRectMake(25, 25, 100, 100)];
[self.actionBtn1 setFrame:CGRectMake(40, 40, 70, 70)];
[self.actionBtn2 setFrame:CGRectMake(0, 0, 150, 150)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
playBtn.alpha = 1.0;
}
completion:NULL];
}];
}
I have a button that when the app loads it is large and in the centre of the screen. However, when it is pressed i want it to shrink down in size and move to the top right of the screen. There are actually 3 buttons but they all share the same IBAction shown above.
The problem I am having is that depending on when the button is pressed the images of the buttons morph into random weird shapes that i did not specify. The images should be perfectly circular but they tend to be redrawn elliptically. Any idea how to stop this?
The original dimensions of the buttons before the button is pressed are below.
actionBtn0 = [[UIButton alloc] initWithFrame:CGRectMake(60, 185, 200, 200)];
[actionBtn0 setImage:[UIImage imageNamed:#"bigLineRing.png"]
forState:UIControlStateNormal];
[actionBtn0 addTarget:self action:#selector(actionButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:actionBtn0];
[self.view bringSubviewToFront:actionBtn0];
actionBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(90, 215, 140, 140)];
[actionBtn1 setImage:[UIImage imageNamed:#"smallLineRing.png"]
forState:UIControlStateNormal];
[actionBtn1 addTarget:self action:#selector(actionButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:actionBtn1];
[self.view bringSubviewToFront:actionBtn1];
actionBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(10, 135, 300, 300)];
[actionBtn2 setImage:[UIImage imageNamed:#"theEye.png"] forState:UIControlStateNormal];
[actionBtn2 addTarget:self action:#selector(actionButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:actionBtn2];
[self.view bringSubviewToFront:actionBtn2];
Instead of using this creation of UIButton;
actionBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(90, 215, 140, 140)];
[actionBtn1 setImage:[UIImage imageNamed:#"smallLineRing.png"] forState:UIControlStateNormal];
try to use this:
actionBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
actionBtn1.frame = CGRectMake(90, 215, 140, 140);
[actionBtn1 setImage:[UIImage imageNamed:#"smallLineRing.png"] forState:UIControlStateNormal];

UIButton not working on animated subView

I want to add two buttons to a subview that appears over the parent view when the view will appear. The buttons are initialized correctly and appear but they donĀ“t react when pressed. Does anybody know why? Here is my code:
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor blackColor];
//Animation View
imageView= [[UIImageView alloc] initWithFrame:CGRectMake(0, 499, 320, 0)];
imageView.image = [UIImage imageNamed:#"trans.png"];
[imageView setClipsToBounds:YES];
[imageView setContentMode:UIViewContentModeBottom];
[self.view addSubview:imageView];
[UIView animateWithDuration:1.0f
delay:0.5f
options:UIViewAnimationOptionCurveEaseOut
animations:^(void) {
imageView.frame = CGRectMake(0, 92, 320, 320);
}
completion:NULL];
[self.view bringSubviewToFront:imageView];
// Animation View Buttons
//1 Amazon
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *button=[UIImage imageNamed:#"button.png"];
[button1 setImage:button forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 290, 80, 30);
button1.backgroundColor=[UIColor whiteColor];
button1.showsTouchWhenHighlighted=YES;
[button1 addTarget:self
action:#selector(openAmazon:)
forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:button1];
//2 iTunes
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setImage:button forState:UIControlStateNormal];
button2.frame = CGRectMake(82, 290, 80, 30);
button2.backgroundColor=[UIColor whiteColor];
button2.showsTouchWhenHighlighted=YES;
[button2 addTarget:self
action:#selector(openiTunes:)
forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:button2];
}
you need to use the option UIViewAnimationOptionAllowUserInteraction
...
options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
...
Make sure you set the userInteractionEnabled property on the imageView:
[imageView setUserInteractionEnabled:YES];
[self.view bringSubviewToFront:imageView];
you are bringing your image view to the front after increasing its frame, this is blocking the buttons actions

NavBar\Toolbar button text color?

I am using the following code to create my toolbar buttons....I would like to change the text color to black or better yet ...set the background image to color the text .....setBackgroundColor would not work....any help is appreciated, Thanks.
UIButton *btnEditLogin = [UIButton buttonWithType:UIButtonTypeCustom];
[btnEditLogin setBackgroundImage:[UIImage imageNamed:#"btnPlain.png"] forState:UIControlStateNormal];
[btnEditLogin setTitle:#"Edit Login" forState:UIControlStateNormal];
[btnEditLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnEditLogin.titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:12.0f];
[btnEditLogin.layer setCornerRadius:5.0f];
[btnEditLogin.layer setMasksToBounds:YES];
[btnEditLogin.layer setBorderWidth:1.0f];
[btnEditLogin.layer setBorderColor: [[UIColor brownColor] CGColor]];
btnEditLogin.frame=CGRectMake(0.0, 100.0, 90.0, 30.0);
[btnEditLogin addTarget:self action:#selector(LoginBtn) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *editLoginItem = [[UIBarButtonItem alloc] initWithCustomView:btnEditLogin];
You can just use the titleView attribute of NavigationItem to do what you need to do. You can do the following:
UILabel *myLabel = [... enter all the code you want to customize the text, etc here];
self.navigationcontroller.navigationitem.titleView = myLabel;
And you should be done... unless I'm misunderstanding the question.
Use this code to change toolbar textcolor.
UIBarButtonItem *barButtonAppearance = [UIBarButtonItem appearance];
[barButtonAppearance setTintColor:[UIColor redColor]];

Image in UIButton is darker tharn original

I'm trying to add a UIButton in a cell which already has a UIImageView in the background.
I put this code in configureCell
UIButton *mail = [[UIButton alloc] initWithFrame:CGRectMake(10, 270, 40, 40)];
[mail setImage:[UIImage imageNamed:#"mail.png"] forState:UIControlStateNormal];
mail.backgroundColor = [UIColor whiteColor];
[mail addTarget:self action:#selector(sendMail) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:mail];
It works but the image in the UIButton is seems darker
I tried these but it didn't changed anything
mail.alpha = 1;
[cell.contentView bringSubviewToFront:mail];
Does anyone have an explanation for this, and a solution as well.
I had the same problem once and I solved it by setting the button's image for the UIControlStateHighlighted
[mail setImage:[UIImage imageNamed:#"mail.png"] forState:UIControlStateHighlighted];
Hope it works for you
Try this
UIButton *mail=[UIButton buttonWithType:UIButtonTypeCustom];
mail.frame= CGRectMake(10, 270, 40, 40);
[mail setImage:[UIImage imageNamed:#"mail.png"] forState:UIControlStateNormal];
mail.backgroundColor = [UIColor clearColor];
[mail addTarget:self action:#selector(sendMail) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:mail];

UIButton to show BackgroundImage, Image and Title

I want to create a UIButton that uses its setBackgroundImage, setImage, and setTitle properties, but when I add setTitle in combination with setImage and setBackgroundImage the title doesn't appear.
I've tried the following.
[button setBackgroundImage:[UIImage imageNamed:#"image3.jpg"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"month_pct_general.png"] forState:UIControlStateNormal];
[button setTitle:[NSString stringWithFormat:#"%d",[button tag]] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20.0f]];
[button setTitleEdgeInsets:UIEdgeInsetsMake(45, 0, 0, 25)];
your title on button and on title your all image it there so add label on the image like this.
UIButton *myButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
[myButton setFrame:CGRectMake(0,3,70,32)];
[myButton setImage:[UIImage imageNamed:#"image.png"] forState:UIControlStateNormal];
[myButton addTarget:self action:#selector(compete) forControlEvents:UIControlEventTouchUpInside];
UILabel *Label=[[UILabel alloc]initWithFrame:CGRectMake(6, 5, 60, 20)];
[Label setText:#"label"];
Label.backgroundColor=[UIColor clearColor];
[Label setFont:[UIFont fontWithName:#"Helvetica-Bold" size:12]];
Label.textColor=[UIColor whiteColor];
[myButton addSubview:Label];
your all image above the title only so your title is in background so use label on image view.
If you are making GUI using interface builder, then click on the label and go to Editor-> Arrange -> Send to Front.