Add programmatically clickable Button with custom Views layouted in InterfaceBuilder - iphone

I have a UIScrollView.
In there I add buttons programmatically.
Right now I just use UIButton and set one title. But I need to have an UIImage View in there, that will change upon certain events, Text that will change too etc. and I would like to style that in Interface Builder, but I can't figure out how to do this. Which class should I extend, and what kind of xib should I create and what in there, so that in the end I can make the right connections and so that I can listen for UIControlEventTouchDown of that Button.

Just make a UIViewController subclass with a nib. You can do everything you want from there.

Related

How to create my own UIAlertController in Swift 5?

I have graphic that I would like to create as a UIAlertController? Can I create a xib and then call that file to present it? What is the best way to do this?
An alert is nothing but a presented view controller. So make your own view controller and call present. It's as simple as that.
You can create a subclass of UIView and its corresponding Xib.
Just create an instance whenever you need to use it and just add it as a subview.
And on the tap of close button just remove it.
Make sure that you create a method in the UIView subclass, which accepts the text, and the button titles, and call the method whenever you are adding it.
So you can add dynamic button titles or texts if the same popup is being used in multiple places in your application.

iOS Storyboard How to access the controls and add event handlers, and binding data to controls added on Storyboard

I used to create the UI thru code. But now I have to use storyboard. I am confused about how to add the event handlers to the controls added on the storyboard and how to bind the data dynamically to the controls added on storyboard. A sample scenario is An UIView is added on the storyboard and two UITableViews and a button are added on top of it. I want to add event handler to the button and bind data to the table views. How do I do this. If I subclass the UIView added on the storyboard will I have access to the controls(button, two table views) added on top of the view or how else I should achieve this ?. Please help !
Adding an event handler to a button is relatively simple. In your UIViewController subclass simply add a method similar to the one below, then in your interface builder select the viewcontroller and on the right side panel click the right most button at the top which looks like an arrow pointing to the right. under received actions drag the circle to the button that you want to perform the action.
-(IBAction)doSomething:(id)sender{
//code for doing what you want your button to do.
}
A separate way you could do it, if you still want to do it programatically is to do the same thing you're used to doing, except in your .h file add IBOutlet UIButton *buttonName; and in the right pane under outlets you'll see your button. which can then be referenced by name within the .m file.

How to define a custom keyPad in my App?

I want define a custom keyboard in my App,When I press one TabBar Item in my UITabBarController, then custom keyboard slide up, when I touch the the tabview, I hope the custom keyboard can slide down, But, Because the custom keyboard add in UITabBarController's view, and tableView add in UIViewController one of UITabBarController's ViewController, they are not in the same Class, How can I define the Keyboard, and add to which view?
I want to do like this:
When Press tab bar Item keyboard slide up,
http://i.stack.imgur.com/66NDu.png
When touch tableview, keyboard slide down.
http://i.stack.imgur.com/ZiHaR.png
Make a custom UIView with your custom keyboard buttons.
UITextField and UITextView have a property called inputView. If you set your custom view to this, iOS automatically takes care of resignFirstResponder and becomesFirstResponder messages on the text field.
This is the easiest way to use a custom keyboard.
Why are you declaring the custom keyboard in the UITabBarController class ? You can declare it in the view controller that is attached to that particular tabBarItem. If you add it to the that view controller, I am sure you can just make it resignFirstResponder or removeFromSuperView and manipulate it as you want.
Or you can just create a separate class for your customKeyboard, and add it along with your other classes. Simply include that class and create objects in other view controllers to manipulate them, and then release them. This is very easy and it is better programming compared to your approach, as at a later point of time, if you need to make changes or release 2.0 version of your app, it will come in handy and save some development time !

Switchable subview in window for iphone app

I've been looking everywhere but can't seem to find any examples/tutorials for my situation (not sure how to google it..)
So i have a window where a portion of it should be static (buttons and such) and there is a dynamic part (bottom leftish) that should change subviews.
So what i'm looking for is a way so that clicking the buttons in the static area will change the dynamic area to a view of my choice. I have no idea how to do this using the IB, but doing it programatically seems the only way. Any suggestions(I do not want to use a tab bar controller)?
Oh, and is there a benefit to making views and such programatically vs through the IB?
Thanks!
You can also achieve it programatically. Just create another viewcontroller class (as many as u want). In the loadView method of it create a UIView in the coordinates where u want to add the subview in the current view. Now create an instance of this viewcontroller class in the currentview controller and add it as a subview. You will get the subview at the desired location.If u want to change it dynamically create as many views and then add them to the array and change them whenever the button is clicked.
Hope this helps.
You should perform the switch in your view controller. The static buttons can have their actions hooked up to that controller (in IB), which can have an outlet (in IB) to the subviews and perform the swap.
As for when you should use IB, see this question.
You can do it from interface builder as well. You just need to take viewController from interface builder drag-n-drop to main window. assign IBAction to all buttons to add different viewController's view to main window just make their frame some smaller.
if u want to change or views by click on button then u chose segmentcontrol switch. and cod for each segment like as when click on segment 0 then open first sub view and when click on segment1 then open second sub view. And make by default unselected so that ur static view will appear initially lunching of view.

iPhone : How to display a common button on my all view?

I want to put button which should be displayed on my all view.
The way we are implementing Tab Bar. I want to implement buttons.
Where should I put that button ? And where should I give its functionality ?
Create your button on main window (i.e. UIWindow) and keep front always after when you loading view.
How many views are we talking about?
If we're just talking about a few views, it probably makes sense to just include similar-looking buttons on each view. If we're talking about many views, then you'll probably want to look at other options.
One solution would be to create a subclass of UIViewController that sets up the button and contains the button's action. The controllers for each view would then be subclasses of that class, so that each inherits the button and action.