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

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.

Related

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 make a floating/3D Touch style tableview?

So i'm making an application for tracking livestock. I have made a table view for the animals to go in. I have a navigation controller at the top with a button in side of it.Here is what i have so far.
I would like to have a floating table view come up when the button is pressed similar to the 3D touch menu.
Like these.
My question is how would i go about doing this. Sorry if this is a commonly done thing im pretty new to swift and xcode
If you just wanna to implement,you could search the key words as 'pop over', 'kxmenu' or 'menu' on GitHub/CocoaControls. such like this: https://github.com/zpz1237/NirKxMenu https://github.com/liufengting/FTPopOverMenu
Also, you should make it yourself. When the button is pressed, first you should create a custom window and make it key window. Secondly, add a tableView or a view contains tableView to the custom window. then, use block or delegate to deal with data communication and respond user interaction. After that, design animation you need. At last, remove subviews from custom window and make the original window key window.

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

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

How can I post a manufactured event to UIButton

I'm writing a simple iOS 6.1 game. The game involves pressing buttons (OK, it's a tictactoe board, with the cells being UIButtons). The allows the player to choose whether to go first, or whether the computer should go first. If the player tells the computer to go first, I want to set some values, and then fire off the UIButton just as if the user had pressed it.
How can I post an event, or otherwise simulate the action of the button being pressed, to let the rest of the framework do the work of handling the button press?
If there is a better design approach, where I don't have to pretend that the computer has pressed a button, I'm open to hearing about that, instead.
Thank you
Your button will be connected to an action method, typically in your view controller. Just call that method yourself, passing the button as the sender.
Your method will be something like:
-(IBAction)buttonPressed:(UIButton*)sender
{
// Respond to your button press...
}
You'd call it as follows:
[self buttonPressed:self.whicheverButtonYouLike];
You'd need the buttons defined as outlets for this to work.

Resources