这个黑客会不会让苹果大发雷霆?(拒绝我的应用程序吗?)

Mad*_*dav 4 iphone xcode cocoa-touch

我从这里获取了这段代码

更改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]];
Run Code Online (Sandbox Code Playgroud)

由oxigen发布的.

我不太确定我应该在我的应用程序中使用此代码.苹果会不会有任何关于这个黑客的问题(他们会拒绝这个应用吗?)

Bra*_*son 10

下划线作为您正在访问的属性的前缀(_titleLabel,_bodyTextLabel)清楚地表明这些是私有属性,不应该被修改.Apple最近开始扫描所有提交的二进制文件以访问私有方法和属性,这些值在您的应用程序中自行应该足以让您被拒绝.使用私有API,拒绝或拒绝是绝对不是一个好主意,因为它们通常是私有的,并且可能会因未来的操作系统更新而破坏您的应用程序.

此外,您通过更改警报颜色违反了iPhone人机界面指南:

您可以在警报中指定文本,按钮数和按钮内容,但无法自定义警报本身的背景外观.

再次,从iPhone人机界面指南:

由于用户习惯于这些视图的外观和行为,因此在应用程序中始终如一地正确使用它们非常重要.