ios

有时,不希望别人使用某个父类方法,比如,写了一个继承NSObject的类,不希望别人用init方法实例化。

那么可以通过这个方法禁止掉,并且报错提示给别人:

1
2
3
4
5
6
 #ifndef DOXYGEN_SHOULD_SKIP_THIS

 // Disallow init and don't add to documentation
 - (id)init __attribute__((unavailable("init is not a supported initializer for this class.")));

 #endif


ios

需求:将UIAlertView的button文字改成指定颜色:

代码如下:

1
2
3
4
5
6
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"设置按钮为红色" delegate:nil cancelButtonTitle:@"我是红色" otherButtonTitles:nil];

[[UIView appearance] setTintColor:[UIColor redColor]];

[alertView show];      

然后要在点击按钮的时候将tintColor置空,因为默认UIView appearance的tintColor是为nil的:

1
2
3
4
5
6
+ (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
  if (buttonIndex == [alertView cancelButtonIndex]) {
      [[UIView appearance] setTintColor:nil];
  }
}
-

Copyright © 2015 - 徐佳琦 - Powered by Octopress