How to create IBOutlet one handed? - ios

For a disabled person (can only use one hand), is it possible to create an IBOutlet and IBAction in iOS programming?
At the moment we use ctrl, click drag however it is impossible for disabled person to do this. Any accebility tricks for them?

Create the IBOutlet or IBAction in code first. Then in your storyboard or xib, click on the thing that owns said IBOutlet or IBAction. Now, in Xcode's menu bar, go to View->Inspectors->Show Connections Inspector. Click down inside the little circle next to the name of the outlet/action that you're trying to connect, and drag your mouse over to the view (or whatever) that will be your outlet (or if you're trying to connect an action, then drag to the button or gesture recognizer or whatever that will be performing the action, and then select the appropriate event, like touchUpInside for a button for example).
Also, I recommend turning on Sticky Keys in your macOS settings if you can only use one hand (located at Settings->Accessibility->Keyboard->Enable Sticky Keys). This will let you press modifier keys down and then use that same hand to press other keys and still perform the key combination.

Related

Create a custom UIButton with text and icon

I would like to create a custom UIButton looking like this:
The idea is simple, I want the titleLabel to start 24px from the leading, and stop 12px or more to the icon image (which is the square view at the right of the button). It can contain up to 2 lines.
The thing is that I have no idea where I should put this code in a class inheriting from UIButton.
What should go into draw(_ rect: CGRect)?
Also, should I use the titleLabel and titleEdgeInsets UIButton properties and the imageView/imageEdgeInsets as well, or instead use custom properties for this?
You just want these buttons to work, be tapped, and react somehow?
These buttons are custom buttons, and you may a create a Cocoa Touch Class file for them; name it and let it inherit from and be a subclass of UIButton.
Then connect that file to your buttons in the storyboard.
But first, you need to set/attach the newly created file to your buttons. Click on the button, In the identity inspector of your storyboard, with your button selected go to the Class field and type the name of your new file and don't forget to tap 'return' to save your changes.
Now, your buttons are attached to that custom UIButton class.
From now, you can attach all your icon images and many more as outlets to your custom UIButton Class you just created.
Most importantly, now these buttons can be used on their own; they can be outlets or trigger action methods. And to make it look just as you except, you just have to initialize your buttons, i.e. provide an icon image, text, etc.
Is what I wrote clear?
If not, I am glad to help you.

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.

iOS Objective-C Controlling Button Images

I have a button. Unsure if it is specifically a UIButton class type. This is a Button which was dragged from the Object library into my Main.Storyboard.
I don't have text, instead I have an image. And I plan to use two images. One for "loop on" and the other for "loop off". I'm playing a sound and this button controls whether or not you will loop the sound. I'm all set with understanding how to do the looping versus not.
I have set the "loop off" image as my default image under the Attributes inspector.
So when the button gets touched, I'll change the behavior of my playing sound to be "loop forever" and I'd like to change the image of the button from within my IBAction function.
I can set a title for the button in the Attributes inspector.
But I don't see that title as a resource name (auto-typing-complete) from within my ViewController.m code.
I know there are properties per state for images. I believe there's also just a "setImage" action for a UIButton.
What I can't determine is how my Button is named in the code because this button was added via dragging it out of the Object library.
Anyone have any knowledge of where these resources get named, like a reference file?
A search found something close, the following link:
http://ranga-iphone-developer.blogspot.com/2011/08/how-to-change-uibutton-image.html
However the solution doesn't appear to reference a particular button name, title, or ID; unless the text "button" is supposed to be replaced with the specific resource name.
Have you added an IBOutlet for this UIButton in your code. If not see the link
You have to create outlets inside the code for your elements added in storyboard. After that you can programatically modify the properties of the elements.
Take a look at this for IBOutlets Link on Outlets
Create a property for the button in the view controller header
#property (nonatomic, strong) IBOutlet UIButton *yourButton;
Then link the outlet in the Interface Builder (i.e. control drag from the controller to the button) and select yourButton, now you can change the title, color and images of the button by using yourButton.

iOS - change animation when user taps screen

Lets say that i have an animation - an image is going from left side of the screen to the right. I would like to make it a little bit interactive - when user taps on a screen i want to change direction of image movement. Whats the best approach to implement it?
What I do in some cases is take the main view of the View Controller, in Storyboard, and change the class type of that UIView to UIControl.
In the code that is accessed as MyViewController.view, which you can write:
var viewAsControl = myViewController.view as UIControl
In Swift or some equivalent of that.
The UIControl subclass of UIView is the hierarchical layer (class) that adds the action/target facilities to a view. For example, UIButton is a UIControl, because it generates events (actions), and it is also a UIView so it can be added as a subview.
Then from the Connections Inspector, accessed via the far right Icon of the far right panel (that is, the panel to the right of the storyboard editor window), I'd select the Touch Up Inside event type or some other event and drag it to an #IBAction tagged function I'd add to the View Controller's source code, to receive the tap event. From that tap notification, you can cancel the current animation and add a new one, etc...
Alternatively, you can create an IBOutlet for the view if you've turned it into a UIControl in IB, and use the addTarget() method to assign an action handler for a specific event, e.g. to make it call a function in your code.
Either way the effect will be that any time the view is tapped, it will generate the event for you to respond to

I can not connect view controller to code using windows keyboard

I started to learn IOS development. I am going through a video tutorial. The instructor is connecting the Hello World to the code by pressing control and using the mouse, as you can see in the screenshot :
I have windows 7 machine. I rented a mac VM from xcodeclub. When I tried to press control and connect the viewcontroller to the code by dragging mouse as done by the instructor, it do not connect. I am using windows keyboard. So how to do this ?
Is any other way to do this ? Or I have to use some other key + mouse drag ?
Fix. Try right clicking on the label and dragging from new referencing outlet.
Otherwise, check to see if your view controller is the correct class. Click on your storyboard file (probably called main.storyboard or something similar) and select the graphical representation of your view controller. Then, on the right hand side click on the small icon that is the 'identity inspector'. Make sure under custom class it displays UIView. If it doesn't, change it to UIView and try again.
If that doesn't work make sure you're dragging the blue line across the screen so that when you release it you are between the #interface and #end lines of code. Like this:
#interface
// drag it here...
#end

Resources