addtarget

Custom UIView: UIButton addTarget not called

瘦欲@ 提交于 2019-12-25 08:46:55
问题 My problem is that I have a custom UIView, which is representing a popup. Inside this view I want to have a slider, which has a label that gets updated every time I drag the slider around. The slider logic works, at least when I'm using it in a ViewController directly, but not with with my custom view. Specifically, the method specified in addTarget doesn't get called at all. I also tried setting the backgroundColor of the slider to something, and it actually showed up, meaning it has a frame

How to 'addTarget' to UILabel in Swift

心不动则不痛 提交于 2019-12-22 04:11:11
问题 I am trying to add labels in Swift, which are added in a loop. I then want to add a 'TapGesture' event to each one as they are added. It works , but the problem is that the function called takes data from the label to use when it's clicked, but the label has been redefined by then and it takes data from the last one added, not the one that was clicked. How can I make each one unique? self.label.attributedText = self.myMutableString let tapGesture = UITapGestureRecognizer(target: self, action:

How to 'addTarget' to UILabel in Swift

馋奶兔 提交于 2019-12-22 04:11:01
问题 I am trying to add labels in Swift, which are added in a loop. I then want to add a 'TapGesture' event to each one as they are added. It works , but the problem is that the function called takes data from the label to use when it's clicked, but the label has been redefined by then and it takes data from the last one added, not the one that was clicked. How can I make each one unique? self.label.attributedText = self.myMutableString let tapGesture = UITapGestureRecognizer(target: self, action:

Programming a UIButton is not working in Swift 4 Xcode 9 Beta 6, Cannot add target

不想你离开。 提交于 2019-12-21 07:14:11
问题 In the past I had no problem creating a UIButton programmatically, but ever since I've been using Xcode 9 and Swift 4, I cannot find a way to make this error go away. //Adding target to UIButton func PositionStartButton(xOffset: Float){ StartButton.frame = CGRect(x: Int(0 - 40 + xOffset), y: 0, width: 80, height: 80) StartButton.setImage(#imageLiteral(resourceName: "Logo_Final_WHITE_Face"), for: .normal) StartButton.addTarget(self, action: "pressButton:", for: .touchUpInside) ScrollView

Adding a closure as target to a UIButton

拜拜、爱过 提交于 2019-12-17 04:52:31
问题 I have a generic control class which needs to set the completion of the button depending on the view controller.Due to that setLeftButtonActionWithClosure function needs to take as parameter a closure which should be set as action to an unbutton.How would it be possible in Swift since we need to pass the function name as String to action: parameter. func setLeftButtonActionWithClosure(completion: () -> Void) { self.leftButton.addTarget(<#target: AnyObject?#>, action: <#Selector#>,

ios Create new file and add to all target automatically

↘锁芯ラ 提交于 2019-12-12 12:12:19
问题 Currently, I have 2 target like this. When I create some file, it only choose 1 for default like this. I have to choose all target manually. I afraid that developers might make some mistakes and don't add to app store version. Is there any way to automatically select both target? Or at least, by default, App Store version should be selected. 回答1: There's an Xcode plugin here that precisely does what you want. 来源: https://stackoverflow.com/questions/36836002/ios-create-new-file-and-add-to-all

Press-and-hold button for “repeat fire”

我的未来我决定 提交于 2019-11-27 13:57:32
I have referred to countless other questions about a press-and-hold button but there aren't many related to Swift. I have one function connected to a button using the touchUpInside event: @IBAction func singleFire(sender: AnyObject){ //code } ...and another function that is meant to call the function above repeatedly while the same button is held down, and stop when the button is no longer pressed: @IBAction func speedFire(sender: AnyObject){ button.addTarget(self, action: "buttonDown:", forControlEvents: .TouchDown) button.addTarget(self, action: "buttonUp:", forControlEvents: .TouchUpOutside

Adding a closure as target to a UIButton

拜拜、爱过 提交于 2019-11-26 21:54:25
I have a generic control class which needs to set the completion of the button depending on the view controller.Due to that setLeftButtonActionWithClosure function needs to take as parameter a closure which should be set as action to an unbutton.How would it be possible in Swift since we need to pass the function name as String to action: parameter. func setLeftButtonActionWithClosure(completion: () -> Void) { self.leftButton.addTarget(<#target: AnyObject?#>, action: <#Selector#>, forControlEvents: <#UIControlEvents#>) } Armanoide NOTE: like @EthanHuang said "This solution doesn't work if you

Press-and-hold button for “repeat fire”

感情迁移 提交于 2019-11-26 16:27:20
问题 I have referred to countless other questions about a press-and-hold button but there aren't many related to Swift. I have one function connected to a button using the touchUpInside event: @IBAction func singleFire(sender: AnyObject){ //code } ...and another function that is meant to call the function above repeatedly while the same button is held down, and stop when the button is no longer pressed: @IBAction func speedFire(sender: AnyObject){ button.addTarget(self, action: "buttonDown:",