I have a working UIalert view with text field and 2 buttons.
I want the text in the message to be a bit bigger, how can I do it?
thanks,
Shlomi
The UIAlertView cannot be changed. If you wish to modify it, you will need to create your own from scratch.
Please see the UIAlertView Class Reference, and under 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.
Related
As I said of title, is it possible to send an image to an UIAlertView to show as the title?
Other way I can do this is showing no title and sending the image as content and after the image, show the rest of the text.
Thanks in advance.
No, the UIAlertView does not support images in the title. Also you should not attempt to insert your own UIImageView in UIAlertView as stated in the official documentation :
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.
Just create you own view which you present, you can present it in it's now UIWindow to roll you own alert view.
With pre-iOS 8 we had to use the UIAlertView and UIActionSheet
Which we weren't allowed to mess with the view hierarchy or subclass on either them.
UIAlertView Documentation
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.
UIActionSheet Documentation
UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:.
However with iOS8 Apple have introduced UIAlertController to replace both UIAlertView and UIActionSheet (Check the pre-release documentation here).
So in this pre-release documentation there is nothing about not being able to subclass or change the view heirarchy, it even has this method addTextFieldWithConfigurationHandler: so will we be able to change the view heirarchy and/or subclass UIAlertController without worrying whether Apple will approve or reject our applications?
It's a late response, but directly from Apple docs.
The UIAlertController 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.
So, you shouldn't subclass UIAlertController.
This answer is outdated. Please refer to limon's answer.
ViewController != View. Apple's policy of not changing the appearance of an UIAlertView does not affect the presenting view controller. I see no reason why you shouldn't be able to subclass the UIAlertController. But using it may be making it harder to replace the alert view with something custom grown, as the alert view is now only created indirectly by classes out of your control. And for UIAlertView same rules applies as before.
Dimming the background upon showing an UIAlertView seems the default behavior of iOS. Can I disable this effect so that the background will not be dimmed, because I have a rather dark background already. Thanks!
UIAlertView doesn’t provide a way to do that. If you need that behavior, you’ll have to find a third-party alert view that does or create your own custom one.
You can't do that with the built-in UIAlertView class from Apple. Try checking out this custom alert view class, although you will need to further customize it to remove the background on the pop-up. Other than that, you could make a custom class from scratch.
I needed to add a UIKeyboardTypeDecimalPad keyboard to a decimal field, which can only be done programatically. I need the full code (I'm pretty new to Objective-C) to make a UIKeyboardTypeDecimalPad pop up when someone touches inside the text box. I'd also like to add the text field programmatically.
Basically, I need to add a text field with a UIKeyboardTypeDecimalPad keypad. Or, if possible, just the keypad to a text field made in Interface Builder.
Does anyone know a good tutorial for this or can anyone give me the full code themselves, and tell me where I need to put it (the .m or .h or what?)?
Thanks!
Update: As mentioned in the comment below, could I see example code for an app that does this?
To set the keyboard type to UIKeyboardTypeDecimalPad, just assign that value to the text field's keyboardType property.
textField.keyboardType = UIKeyboardTypeDecimalPad;
Adding a text field programmatically is only slightly more work: UITextField *textField = [[[UITextField alloc] initWithFrame:frame] autorelease]; to create it, then set any properties you need to set, and add it to the appropriate view with addSubview:.
In your view controller's viewDidLoad method is a good place for this sort of thing. Or if you're loading a view without a controller from the nib, use the view's awakeFromNib method.
So, I developed a kind of drop down button class.
Let's call it DDButton.
I mainly export one function :
-(void) addButtonWithImage:(UIImage*)image andTarget:(id)target andSelector:(SEL)selector
which lets the user add another button to the drop down.
I will need to use DDButton in different screens of my app.
I would like to use it like:
DDButton* ddb = [[DDButton alloc] initWithFrame:rect];
[ddb addButtonWithImage....]
[ddb addButtonWithImage....]
My question is since I never subclassed UIView before how should I implement it, and how should I use it later ?
Do I use IB and create a stub UIView which I'll connect to the DDButton in the Identity Pane ?
if so , how exactly I instantiate the view later on.
Or,
Do I subclass UIView ? if so , what methods I should override ? Do you I setup my buttons in the initializer ? in LayoutSubView ? In drawRect ?
I would love to hear the best approach here.
Thanks!
Edit
Let's say I choose the IB way : I have a main button which I set regardless of the
addButtonWithImage() calls, actually all calls to addButtonWithImage just "append" to that button. I want to main button to be the size of the view, until other buttons are added and then the view grows appropriately. However, I want the size of the view to be chosen by the user at first...using setFrame I guess.
Meaning in the awakeFromNib I can't count on the frame size yet (it only take the xib size I assume). So where would I setup my main button ? LayoutSubView ? setFrame ? I'm not sure.
Add your view to the interface in IB as a UIView, then change the class in the identity pane. If you need to do initialization in code, use a -(void)awakeFromNib method. I would suggest setting up the buttons when they are added in addButtonWithImage....
I'd probably do a subclass, building views in code is a good thing to learn.
Override drawrect: to do any custom drawing you need to do, if you're just adding a UIImageview or something and doing positioning you could just override initWith...: and do your custom initialisations.