uibutton

How to change button image in swift?

扶醉桌前 提交于 2020-01-12 06:06:09
问题 I am working on an app which has a button. The button has no text, image or background. So what I want to do is to give it an image in the viewDidLoad function. This is what I have: @IBOutlet var tapButton: UIButton! override func viewDidLoad() { super.viewDidLoad() tapButton.setImage("redTap.png", forState: UIControlState.Normal) } But I have an error that says I can not convert string to UIIMage. How do I get it to work? I have tried: let image = UIImage(named: "redTap.png") tapButton

How to change button image in swift?

北慕城南 提交于 2020-01-12 06:05:23
问题 I am working on an app which has a button. The button has no text, image or background. So what I want to do is to give it an image in the viewDidLoad function. This is what I have: @IBOutlet var tapButton: UIButton! override func viewDidLoad() { super.viewDidLoad() tapButton.setImage("redTap.png", forState: UIControlState.Normal) } But I have an error that says I can not convert string to UIIMage. How do I get it to work? I have tried: let image = UIImage(named: "redTap.png") tapButton

How to change button image in swift?

拈花ヽ惹草 提交于 2020-01-12 06:03:10
问题 I am working on an app which has a button. The button has no text, image or background. So what I want to do is to give it an image in the viewDidLoad function. This is what I have: @IBOutlet var tapButton: UIButton! override func viewDidLoad() { super.viewDidLoad() tapButton.setImage("redTap.png", forState: UIControlState.Normal) } But I have an error that says I can not convert string to UIIMage. How do I get it to work? I have tried: let image = UIImage(named: "redTap.png") tapButton

UIButton not calling action in iOS 5 but works in iOS 6

孤者浪人 提交于 2020-01-12 02:43:13
问题 I have a UIButton that is loaded from a xib file as an IBOutlet property of a view controller. I attach a selector to the button in the viewDidLoad of my view controller: [_myButton addTarget:self action:@selector(mySelector) forControlEvents:UIControlEventTouchUpInside]; In iOS 6 everything works, but when i run on the simulator in iOS 5.0 the selector doesn't get called. The button does highlight when it is touched. Another thing to note is that the button is in a UIView that has a

UIButton not calling action in iOS 5 but works in iOS 6

China☆狼群 提交于 2020-01-12 02:43:05
问题 I have a UIButton that is loaded from a xib file as an IBOutlet property of a view controller. I attach a selector to the button in the viewDidLoad of my view controller: [_myButton addTarget:self action:@selector(mySelector) forControlEvents:UIControlEventTouchUpInside]; In iOS 6 everything works, but when i run on the simulator in iOS 5.0 the selector doesn't get called. The button does highlight when it is touched. Another thing to note is that the button is in a UIView that has a

How do you change UIButton image alpha on disabled state?

六眼飞鱼酱① 提交于 2020-01-11 23:00:44
问题 I have a UIButton with an image and on its disabled state, this image should have .3 alpha. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *arrowImage = [UIImage imageNamed:@"arrow.png"]; [button setImage:arrowImage forState:UIControlStateNormal]; // The arrow should be half transparent here [button setImage:arrowImage forState:UIControlStateDisabled]; How do I accomplish this? UPDATE : I noticed, by default UIButton does reduce the alpha of the image on disabled

Animate UIButton's title change

ぃ、小莉子 提交于 2020-01-11 20:09:39
问题 Here I found how to animate UIButton 's title change using now-deprecated beginAnimations:context: method: UIBUtton title animation for iPhone How to do the same thing using current APIs? Update: I've tried to use block-based animations: NSTimeInterval animationDuration = animated ? 1.f : 0.f; [UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{ [button setTitle:newTitle forState

Animate UIButton's title change

 ̄綄美尐妖づ 提交于 2020-01-11 20:09:30
问题 Here I found how to animate UIButton 's title change using now-deprecated beginAnimations:context: method: UIBUtton title animation for iPhone How to do the same thing using current APIs? Update: I've tried to use block-based animations: NSTimeInterval animationDuration = animated ? 1.f : 0.f; [UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{ [button setTitle:newTitle forState

How to change UIbutton title once a UIbutton is pressed?

[亡魂溺海] 提交于 2020-01-11 12:13:12
问题 I am having trouble changing the title of UIButton btn2 once btn1 is pressed. When I use _definition settitle:@"Show Word" forState: UIControlStateNormal it changes the original btn1. Here is the code for your review, - (IBAction)mynextPressed:(UIButton *)sender { //Display the string in the label field [self.WordDisplay setText:vocabulary]; //reset center button with "show word" [_definitionPressed setTitle:@"Show Word" forState:UIControlStateNormal]; NSLog(@"displaying word: %@",

Can I use a UIBarButtonSystemItem for a UIButton?

落爺英雄遲暮 提交于 2020-01-11 08:34:09
问题 I am trying to customize a UIButton and I want to use a UIBarButtonSystemItem style that is available for a UIBarButtonItem object. How do I use a UIBarButtonSystemItem style on a UIBUtton object? 回答1: You can't. UIBarButton and UIButton are two completely different classes. The best you can do is find images close to what you're looking for and add them to UIButtons. 回答2: Use a UIView instead of a UIButton that contains a UIToolbar with UIBarButtonItems. UIView *buttonContainer = [[UIView