How to add buttons in alertView in different lines? - uialertview

I want to create an alertView that shows 2 buttons- Delete Photo and Cancel.
I want the buttons to appear in different lines. But whenever I try, I get them in the same line.

There is no SDK support for this. Button will appear in one per line if you have more than two button. But for two button it will be in one line.
But its possible by subclassing UIAlertView. But apple says:
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Related

Differentiate between multiple UIButtons with empty titles

I have a bunch of UIButtons (10-15 of them) in one of my Views. I want to display them as an image without the title text, so what I did was set the image for the Button through the storyboard, and then set an empty title for the button.
I want to react differently when each button is pressed. There are a couple of solutions that I can think of off the top of my head, and I'm wondering which would make the most sense, software engineering-wise:
Each button is connected to a different IBAction (too many methods added)
Each button is connected to a different IBOutlet (how to differentiate between the buttons, still? Use ===?)
Single IBAction, unique tags for each button (this is what I'm doing for now as it's simplest and it works, but aren't tags a bit hacky?)
Give each button a different title, but find a way to hide the titles, and then connect them all to an [UIView] outlet array (is it possible to hide the titles from the storyboard, or must I do it programmatically from the View Controller?)
Some solutions you thought of are viable, some others aren't (connecting #IBOutlets and trying use the equal operator, or hiding the button's title).
I would recommend you to simply keep using UIButton tags (as that's what tags are there for) and use a single entry-point #IBAction. You will then be able to identify each button by their tag.
Subclassing your buttons might seem a bit overkill if you're only trying to identify them...

How to add more than eight buttons in a UIAlertView?

I want to add more than 8 buttons in UIAlertView but when I am adding buttons, they are covering each other and not scrolling. The title is also hiding.
How can I resolve this and add some scrolling in the alertview ??
Seems like this kind of question comes up at least once a day on StackOverflow, but if you want to mess around with the various components within a UIAlertView, the short answer is: DON'T.
If you look at Apple's documentation for UIAlertView, within the first screenful of text it states:
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
This means that there's a decent chance that any mucking around within UIAlertView hierarchy could catastrophically break your app in future iOS release.
So if you want to add scroll bars or bells & whistles, you really should create your own custom UIView (which looks like a UIAlertView, but is wholly of your own creation)
If you have more buttons then UIActionSheet is the best option than using UIAlertView. If you dont want to use UIActionSheet there is always a custom View to your rescue!
You should really rethink your UI if you need more that 8 button in a UIAlertView. 8 button is the maximum the standard alert view can handle.
Either build your own alert view or use a normal view controller with a table view.
Not sure if it's necessary but as an alternative, you can present another ViewController/ModalVC that will have all the attributes that you may require....
Just move ahead with CustomView, Otherwise not possible with UIAlertView to meet up with your requirement :
Reference links :
http://iphonedevelopment.blogspot.in/2010/05/custom-alert-views.html
http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
https://stackoverflow.com/a/6965828/434898
If you want to add many buttons you can use a custom implementation for the alertView.
A nice example is FUIAlertView
Or you could use WEpopover and add to it a table view.

How to control the number of simultaneous touches on a view in iOS

I have a UIView which contains almost 10 buttons which performs different actions. The user will be able to touch or tap on any button to perform a required action. But, i am getting a problem when the user presses multiple buttons at the same time. When two buttons are pressed at the same time(simultaneously) two actions are getting performed. Some times the app is getting crashed. So, i dont want the user to tap multiple buttons simultaneously. Is there any way in which i can ask a view to recognize only single touch instead of multiple touches or at least can i increase the time gap between multiple touch gestures...
Use button.exclusiveTouch = YES; on each of your buttons. You will need to hook them up to UIButtons and set the property in viewDidLoad for example
This is a similar post, which has a nice solution. You essentially just hook up all the buttons to the same method, and have a switch statement. Hope that Helps!
Try yourView.multipleTouchEnabled = NO;
"yourView" here is the view contents all of your buttons.

How to put images in action sheet button?

I have created an action sheet which contains more than one button, and I want to put different images on different buttons, how can I do that?
You can't, the "buttons" (actually a special class called a three part button, IIRC) in UIActionSheet are not directly accessible and you can't subclass it either. However it is pretty easy to write your own, see http://blog.corywiles.com/custom-uiactionsheet-using-core-animation for an example or inspiration. It's only a view with some buttons as subviews, and a bit of code to handle sliding it up from the bottom of the screen.

How can I implement an autoselection textbox like the one for e-mail addresses on the iPhone?

On the iPhone's mail app, you can type in multiple mail addresses...and then to delete one you just tap it, and click Del. How can I implement something similar in my app? I tried to handle the tap on a UITextView, but it looks like the touchesBegan and related delegate methods are not fired for this class and its subclasses :(
Any idea?
I have implemented a view that is identical to what is found in the mail.app. I used a composite view comprised of a custom UIView which houses a couple of other types of views. I used a UITextField for the text entry. As the user completes an address I take the text and place it in a button with a custom background image (to get the bubble around the text look) and move the UITextField to the right (or to the next line as the case may be). When the user taps one of the address "bubbles" it is selected. If they hit the delete key I remove that bubble from the view and re-layout everything. This is a non-trivial view to build with lots of fun edge cases.
Check out Joe Hewitt three20 project, it includes "Better text fields" which can do such thing.
This could be helpful: Link
TITokenFieldView
A control which mimics the To: field in Mail and Messages. Kinda like an NSTokenField.