iOS 7 UIDatePicker in UIAlertView customisation - ios

Guys I was adding UIDatePicker to UIAlertView like this
It was fine with iOS 6 and below now in iOS 7 it comes like this
Any ideas why this happens? Is there a better way of doing this?.Any help is appreciated.

You can change accessoryView to any own customContentView in a standard alert view in iOS7
[alertView setValue:customContentView forKey:#"accessoryView"];
Note that you must call this before [alertView show].
Simplest illustrating example:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"TEST" message:#"subview" delegate:nil cancelButtonTitle:#"NO" otherButtonTitles:#"YES", nil];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
v.backgroundColor = [UIColor yellowColor];
[av setValue:v forKey:#"accessoryView"];
[av show];
Exactly in the same way you can add your DatePicker.

This is my component to support addSubview in AlertView.
CXAlertView - Custom alert-view which allow you to add view as main content.

On iOS7, you should use the new custom modal transition support in UIKit using UIModalPresentationCustom and transitioningDelegate.
Using these, you can create a view similar to that of an alert view, but custom, where you could add a date picker.
More information here:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewControllerTransitioningDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intf/UIViewControllerTransitioningDelegate

There is no fix for this. Adding subviews to a UIAlertView was never supported and in iOS 7 this lead to subviews not showing. Some workarounds have been posted on the Apple Developer Forums, but they could easily break in a future release.
I suggest file a bug report. Many others (including myself) have done this, and the more requests Apple gets for it, the higher its priority becomes.
EDIT: I have written a UIAlertView clone that does allow for adding subviews: SDCAlertView.

It is not supported and I dont belive they 'fix this' .. roll your own alert view or use a open source alternative. see also UIAlertView addSubview in iOS7

Related

How to decrease the Font size of a button in UIAlertView,is there any way to do so?

i am using UIalertView,
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:appname
message:#"some blah blah!"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:#"Free content", nil];
[alert show];
here i want to reduce the font size of "Free content" when alert view pops up(something like arial-9)font,is there any way to reduce the font or design it in a custom way?
thanks,
You cannot customize the appearance of UIAlertView,
because the view hierarchy for this class is private and must not be modified.
for more see UIAlertView Class Reference:UIAlertView Class Reference:
why not?
you can use Custom AlertView with desire apperance
see the below link how to create custom alertviews with your desired apperance CustomAlertView Sample
UIAlertView is deprecated as of iOS 8. You need to use UIAlertController from iOS8 onwards. You can use Key-Value coding to set UIAlertController's button font using attributedTitle key.
More on the answer provided here.
UIAlertController custom font, size, color

iOS 8 Alertview action button colors are in white color

alertView action buttons are in blue color till ios 7
But on iOS 8 , "OK" and "cancel" are in White color.
Please find the block of code that creates the alertview
+(UIAlertView*)showWithMessage:(NSString*)message withTitle:(NSString*)title {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:tibbrLocalizedString(#"all_view.ok.button", #"Ok button title for alert")
otherButtonTitles:nil];
[alert show];
return alert;
}
This is the deafualt behaviour of UIAlertView. If you need any customization you can use any custom alertview libraries like,
https://github.com/warrenm/AHAlertView
Note : The UIAlertView follows the whitish theme from iOS 7.0 Onwards
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/Modal.html#//apple_ref/doc/uid/TP40006556-CH64-SW1
Issue that i was facing is due to below line
[[UIView appearance] setTintColor:[UIColor whiteColor]];
/* To customize the appearance of all instances of a class, send the relevant appearance modification messages to the appearance proxy for the class. For example, to modify the bar tint color for all UINavigationBar instances:
[[UINavigationBar appearance] setBarTintColor:myColor];
Note for iOS7: On iOS7 the tintColor property has moved to UIView, and now has special inherited behavior described in UIView.h.
This inherited behavior can conflict with the appearance proxy, and therefore tintColor is now disallowed with the appearance proxy.
*/
+ (instancetype)appearance;
With the above explanation i could infer that tintcolor was being applied to AlertView as well which overrides our customization on alertView

Adding Subview Covers Up Navigation Bar in Navigation Controller

I have a Navigation Controller that at times I need to present a subview for entering a password. The issue is that when I do this, it covers up the navigation bar, making going back in the hierarchy impossible to do. I use XIB for this, but it doesn't give me the option of resizing the UIView that adds on it.
if ([student isEqualToString:#"No"]) {
[self.navigationController.view addSubview:password];
[self.navigationController.view bringSubviewToFront:password];
}
Here are a few suggestions (assuming I understand your issue). Given that you are prompting for a password, I'm assuming you would want the user to either a) provide the password or b) cancel entering the password (not simply ignore it). If they do the latter, then the cancel button could be used to dismiss the password subview.
Suggestions:
Add a cancel button to your subview to dismiss the subview
Use a UIAlertView to present a modal dialog to capture the password with cancel button (see below)
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Password" message:#"Enter your password:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; // masks pwd text
If you're set on your current approach then define the subview similar to the following so that it is offset from the nav bar (or use constraints)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 200, tableView.frame.size.width, 100)];
It'd be helpful if you could provide a screenshot of what you're seeing and an image of the interface design you're trying to build.
The code above looks a little weird. Using addSubview: to add this type of view to your navigationController will likely have unintended consequences.
I would recommend either:
Building your password-entry UI in a new UIViewController subclass and using pushViewController:animated: to add this new viewController to the view hierarchy.
or
Use an alertView to capture the password entry, by either using the system UIAlertView or by building a custom alertView using a UIWindow.
Let me know if you need further explanation / clarification.

UIAlertview valueForKey:#"_backgroundImageView"

I want to change the text color and background color of ui alert view. I was using the following code,
UILabel *theTitle = [alertView valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor whiteColor]];
UILabel *theBody = [alertView valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor whiteColor]];
UIImageView *backgroundImageView = (UIImageView *)[alertView valueForKey:#"_backgroundImageView"];
[backgroundImageView setImage:[UIImage imageNamed:#"background.png"]];
this was working fine in ios 6. But after upgrading to ios 7, this method is not working. I dont want to create custom uialertview. Please suggest any simple solution to fix this.
Starting in iOS7, UIAlertViews are not customizable anymore.
You'll have to stick to their style, or create your own from a UIView, but you cannot change that.
In iOS7, UIAlertView is nothing but a data container. It just takes the parameters you set and displays them in a private view hierarchy on a private window. Your alert view is never added to any view hierarchy.
Either roll your own alert view implementation or use an open source one, like DTAlertView: https://www.cocoacontrols.com/controls/dtalertview

MonoTouch for iPad: How to show a popup dialog?

I just started learning developing an application (primarily) for iPad using MonoTouch. Maybe because of my many years experience in C# world, it makes my switch very difficult, and I feel stupid sometimes. This is very simple thing in C#, but it make me scratch my head...
Popup dialog?
For iPhone, you rarely have this requirement, because whatever you show will occupy the whole screen, so you just create a controller for each popup.
For iPad, I have much more space, and I don't want the whole screen to be occupied with a few controls (e.g. login screen). That's why I want to show it as a popup. I have seen this in other iPad apps.
From what I learned, I need to use UIAlertView or UIActionSheet to do this. But what I don't understand is that, as shown by all the examples I have read, you have to create all the controls from the code.
What I would like to do is to create the UI using IB, and plug it into UIActionSheet. Is it possible? How do I do it?
If this is an iPad-only application, you will want to use a UIPopoverController. This is a popup "window" that contains a view and is linked to an area on the screen, such as a toolbar button or a rectangle (such as the Frame of a UIButton).
To use this, create a new instance of UIPopoverController, using the constructor that accepts a UIViewController and pass the view that you want to show.
Due to garbage collection considerations, make sure that you store the UIPopoverController in a class-level property.
You will probably also want to clean up this property when the popover is closed. To support this, we subclassed the UIPopoverController, added an event that can be hooked by the caller, then overrode the Dismiss method and fire the hooked event, if any, in the overridden method.
Once you instantiate the popover, you will want to show it. You can do this through one of the PresentFromxxx methods. If you are presenting this from a button (not toolbar) you can call PresentFromRect using the button's frame as the rectangle.
The view that is presented can control its size by setting the ContentSizeForViewInPopover property in its ViewDidLoad method.
You can't edit a UIActionSheet or UIAlertView from Interface Builder.
What you can do is create a view in Interface Builder and display it modally over top of your other views, however it sounds like you don't want to occupy the entire screen and this is what would happen. Here is an example of a modal view controller: http://pastebin.com/h221BQdK
I think you should just follow the examples you mention and create a UIAlertView from code, maybe put it a static utility class. I created a MessageBox class to be more like windows, but you can also put text boxes on there for login. Look at the login box on the app store, it is a decent example of what it would look like.
Create a viewcontroller named extraviewcontroller set its height width to 300 * 215 .
and write the code below
inviewdidload
pickerviewTitle = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0, 383, 250)];
pickerviewTitle.delegate = self;
pickerviewTitle.tag = 0;
pickerviewTitle.showsSelectionIndicator = YES;
controller = [self.storyboard instantiateViewControllerWithIdentifier:#"ExtraViewController"];
popovercontroller = [[UIPopoverController alloc] initWithContentViewController:controller];
popovercontroller.delegate = self;
then
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:#"Title" delegate:self cancelButtonTitle:#"Done" destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet1.tag = 0;
actionSheet1.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet1 addSubview:pickerviewTitle];
[actionSheet1 setFrame:CGRectMake(0, 0, 600, 400)];
[controller.view addSubview:actionSheet1];
if ([popovercontroller isPopoverVisible]) {
[popovercontroller dismissPopoverAnimated:YES];
} else {
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect convertedFrame = yourclickbutton.frame;
[popovercontroller presentPopoverFromRect:convertedFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}

Resources