I have taken this code from
Changing the background color of a UIAlertView?
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:#"Atention"
message: #"YOUR MESSAGE HERE", nil)
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[theAlert show];
UILabel *theTitle = [theAlert valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
UIImage *theImage = [UIImage imageNamed:#"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[theAlert layer] setContents:[theImage CGImage]];
orginally posted by oxigen.
I am not very sure should I use this code in my app. Will apple have any issues regarding this hack (will they reject the app?)
The underscores as prefixes of the properties you're accessing (_titleLabel, _bodyTextLabel) clearly indicate that these are private properties and should not be tinkered with. Apple has recently started scanning all submitted binaries for access to private methods and properties, and those values by themselves within your application should be enough to get you rejected. It is never a good idea to use private APIs, rejections or no, because they are typically private for a reason and may break your application with future OS updates.
Additionally, you are violating the iPhone Human Interface Guidelines by changing the alert color:
You can specify the text, the number
of buttons, and the button contents in
an alert, but you can’t customize the
background appearance of the alert
itself.
Again, from the iPhone Human Interface Guidelines:
Because users are accustomed to the
appearance and behavior of these
views, it’s important to use them
consistently and correctly in your
application.
Only Apple can answer that question. And they won't answer it until you submit it and wait approximately 2 weeks.
If you really want it in and have 2 weeks to kill, try to submit it. But it might get rejected at an update later.
Are you using any undocumented APIs here? If you are, assume it will get rejected. If you aren't but you are doing something different, then the only answer to your question which is correct is "I don't know".
If you want to know if some programming technique will result in rejection, make a small app with limited functionality and use your questionable technique in it.
It takes 2 weeks to get an answer but at least you won't invest a ton of time upfront.
If they approve your test app, delete it from the store. If it has genuine utility, set the price to $0.99 and leave it.
This method is not foolproof, but it is low cost.
Related
I am new in iOS. I want to use iToast in my App. I followed toast-notifications-ios
First when I created my iToast.m I got four errors on these lines:
[label release];
[imageView release];
view = [v retain];
iToast *toast = [[[iToast alloc] initWithText:_text] autorelease];
I always have problem with release and autorelease in different examples. I use iOS 5.1, xCode 4.3.3. I saw many examples using them but I always got errors on them. Can you let me know why?
When I commented the first third error lines and use the forth one like:
iToast *toast = [[iToast alloc] initWithText:_text];
I could run the project but when the Toast pops up, it never disappears. I used this line as written in README.md:
[[[[iToast makeText:NSLocalizedString(#"Something to display a very long time", #"")]
setGravity:iToastGravityBottom] setDuration:iToastDurationShort] show];
How can I solve this problem?
If you just started out you are probably using Automatic Reference Counting, or ARC. Using this the compiler handles the memory for you and renders retain, release,and autorelease for you. You can either disable ARC for your project or go through the supplied code and make it ARC compliant by translating retains, releases, and autoreleases.
This explains the differences and how to transition:
http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
I need some modal view on iPhone app where I will display few labels, one UIImageView and two buttons. Design needs to be whole custom.
Is this custom UIAlertView? How to make something similar?
There is a nice blog post by Jeff LaMarche about how to create a custom Alert View. You can take inspiration from there.
http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
** UPDATE on April 24, 2017 **
Unfortunately the blog doesn't exist anymore. However you can retrieve the post from the Web Archive:
https://web.archive.org/web/20160430051146/http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
See the source for Tapku library. They have this option - you can always hack/tweak source code for it. Its not that difficult though, Just a lot of layer magic going around (e.g. the vignette effect). and most of the assets are images. You just need to break it down properly.
You can acquire that simply following the following steps
Create UIview (ViewA)of size 320*480 , so that it will cover whole screen of iPhone with background set to clearColor.This will serve as super view for our purpose;
Create another UIView (ViewB) of size 320*480 with background color set to black and opacity to 40%.
3.Now you can add any view on ViewB.
Now add ViewB to ViewA.
Finally you can Present this view where ever required. The effect will be, ViewA will cover the Background viewController, ViewB will server as suppressing effect for background view controller and views on B are the UIElement you will see.
Making a view like this is simple. You just need to create a custom view with the pieces that you want and just make it hidden or set the alpha to 0.0. Then un-hide it when you want to use it.
To prevent interaction with other items behind the view put a blank semi-transparent view right behind your custom view.
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"\n\Please wait. \n Authorising Credentials..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"smile.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];
[alert addSubview:imageView];
[imageView release];
[alert addButtonWithTitle:#"Cancel"];
[alert show];
I would like to add a bunch of UILabels or NSStrings to the UIALertView since I have run out of space on my display.
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"random" message:nil delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles: nil];
//firstString=[[UILabel alloc]initWithFrame: CGRectMake(12.0, 70.0, 260.0, 25.0)];
[alertDialog addSubview:firstString];
[alertDialog show];
[alertDialog release];
I can tell you from experience that this is a bad idea. In earlier version or iOS there were tricks using undocumented behavior, Apple made changes to the underlaying code and it all broke badly. Just create a UIView the way you like. If you want to dim the rest of the screen just place a semi-transparenr view over the screen and under your view.
You can use a alternative implementation of an alert view. One, that is not a subclass of UIAlertView — so it is absolutely independent to any changes Apple may release. And you have the possibility to add any subview as a clean property.
TSAlertView is such an alternative implementation.
you can use uitextfield to do so ,
simply change textcolor to while , and change background color to clearColor
I want to submit an iPhone application, and I am concerned about the following line of code which add an Image to the UIActionSheet Button:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet addButtonWithTitle:#"Button"];
[[[action valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"yourImage.png"] forState:UIControlStateNormal];
does that compromise any of apple app sumbition rules? is it legal? please tell me if so.
Thanks.
It is not legal, since _buttonsis not a public API.
(I would say however that it would pass Apple's review since you are using KVC and they have no way to know that this is a private call. Still, play safe and don't use it!)
this is the code i have taken form.....
- (void)willPresentAlertView:(UIAlertView *)alertView
{
[[[alertView subviews] objectAtIndex:2] setBackgroundColor:[UIColor colorWithRed:0.5 green:0.0f blue:0.0f alpha:1.0f]];
}
- (void) presentSheet
{
UIAlertView *baseAlert = [[UIAlertView alloc]
initWithTitle:#"Alert" message:#"This alert allows the user to choose between a 'safe' and a 'deadly' choice, indicated by button color.\n\n\n\n"
delegate:self cancelButtonTitle:nil
otherButtonTitles:#"Deadly!", #"Safe", nil];
UITextField *txtFld = [[UITextField alloc] initWithFrame:CGRectMake(60,10,240,31)];
[txtFld setDelegate:self];
[txtFld setBackgroundColor:[UIColor clearColor]];
[baseAlert addSubView:txtFld];
[txtFld release];
[baseAlert show];
}
my question is If it is allowed to change the basic Look and feel of the apple's provided UIControls, because I dont see any reason that apple should not allow this type of customisation.
Alert views have long been standardized to for the same reason things like fire extinguishers and safety signs are standardized i.e. you don't want people to have to puzzle out a new interface while something is going wrong.
In general, it is a bad idea to change something in the interface that has been highly standardized. What benefit will it bring to the end user? Will they think, "Damn, I lost all my data but the alert that told me that sure did look artistic!" More likely, they won't understand that the dialog is actually an alert but rather part of the apps normal functioning.
Having said all that, there is nothing to stop you from creating your own custom view and presenting it modally. That is a far safer and easier route than mucking about under the hood of the Apple API.
I don't know if Apple will reject an app for accessing undocumented subviews, but they certainly recommend against it. In fact, when I was at the iPhone tech talk last week a developer evangelist specifically said not to do this because the implementations will change and your app will break.