How can I give ios UI elements an identifier to use with UIAutomation? - ios

I'm trying to write some UIAutomations for an ios app. Every piece of UI in this application is custom. When using the recorder in UIAutomation, I can choose buttons based on their index. Such as ....
UIATarget.localTarget().frontMostApp().mainWindow().buttons()[1].tap();
Now, some buttons, when pressed with the recorder, show up like this...
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Edit"].tap();
My question is, what do I need to do in the code to uniquely identify every button like how the "Edit" button is identified above. I know this isn't using the tag property because tags must be integers and I just tried to set the accessibiltyIdentifer on a button. However the NSString I used for the accessibiltyIdentifer didn't let me access the button in UIAutomation with that string. So what was done to this "Edit" button that let me access it that way? I'm working in a large code base that I'm very new to so I'm a little lost.

Looks like you want to set both accessibilityEnabled to YES and accessibilityLabel.
myTextField.accessibilityEnabled = YES;
myTextField.accessibilityLabel = #"User Text";
Source - http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation

Related

Xcode program: Text box that the user can interact with through touch

I am new to Xcode and Swift.
I want to create a text box for a video game that acts as the dialogue between the game and the user. for example I want the text box to say (character name) walked 10 paces or "Used 'detect evil' orc within 60'. "
I also want the ability for the user to pressure touch this chat text message which is sent from the computer and then do a series of actions. For example if a paladin detects evil maybe the next course of action would be to hide or prepare to fight. Any ideas on how to set this up? I have been trying to create this on Main.storyboard. Can I only achieve this through the ViewController or one of the delegates?
First of all, you can only achieve this by coding (by using Storyboards as your ally of course!)
If you want to have a text box that is "clickable", what first comes to mind is just a button, that have no background color, so it looks just like text.
Then you need to create a method inside of your ViewController, ideally something like:
#IBAction func dialogBoxTapped(_ sender: Any?) {
// your code goes here
}
And connect your button to this function by setting up a touchUpInside method in the Storyboard.

Using single UIView I want to manage tap action based on location and update specific object

enter image description here
I am making app like sudoku (9*9 boxes) but it has only binary choices (on/off) and using button gave me horrible results. Can anyone give me demo version of 9*9 (or 3*3) box where depending upon the tap location, that specific box gets toggled (on/off)
You could create a custom subclass of UIView that had an attached tap gesture recognizer and interpreted the tap location to figure out which cell is being tapped, but it would be a lot of work.
It would be better to have custom view that contains a grid of buttons and set up the button actions to do what you want.
You said "...using button gave me horrible results." Can you elaborate? That should be a good way to go, so any "horrible results" are likely the result of something you did wrong, rather than that being the wrong way to go.

iOS 10 notification extension: can I change the action button text?

I've been playing around a little with the UNNotificationContentExtension framework to display a custom view inside a notification. So far, so good - got it rendering, and then altering content when a user taps on an action button.
But the one thing I don't seem to be able to do is change the text in the action buttons - not necessarily surprising given that it is defined in a UNNotificationAction I have to declare beforehand, but I'm wondering if anyone has had any luck in finding a way to change the button text?

how to create my own radio buttons

I am new to Swift and Xcode so I need help with what I am doing. And what I am doing is this.
I have three buttons one of them starts out checked. and what I want it to do is when I click on another button it checks it and unchecked the previous. I want my own radio buttons
For Radio Buttons there is nothing that comes built in.
You can use SSRadioButtonsController
You can create a controller object and add buttons array to it like
var radioButtonController = SSRadioButtonsController()
radioButtonController.setButtonsArray([button1!,button2!,button3!])
You can also use something like this tutorial.
The standard Apple class that is designed to work with radio button groups is NSMatrix. Specifically you'd create an NSMatrix with mode "NSRadioModeMatrix". NSMatrix takes an NSCell for its list of items. So you can use any built-in NSCell subclass (like NSButton) or anything else custom you would like.
You can manage manually by setBackgroundImage and setImage property. at initial time set rounded image as setBackgroundImage for all three button. At button click event set "bulletin" image by setImage property for selected button and set nil for all other button setImage property.

why cant I change button title in ios

I am new to ios, and trying to change a simple button text from implementation side in an action.
I have tried two of these: while one of them works, the other one doesnt !
self.Btn_Analyse.titleLabel.text = #"Stop Anlaysing"; // didnt work
And...
[self.Btn_Analyse setTitle:#"Deneme" forState:UIControlStateNormal]; //worked
why doesnt the first one work?
PS: I have connected the button as IBOutlet
Why are you telling us what worked?
If it worked then there isn't a problem.
Anyway, the reason the first one didn't work is because a button is not just a label. It has various states and each state can have different properties.
You set the image for the state. You set the title for the state. etc...
Then with different states you can have different properties.
UIButton sets the title on its own, so if you directly change the text in label, button changes it back.
That's because button can have different titles for different states (label can't do that), and sets the appropriate one automatcally.

Resources