iOS开发已已错已忘知识点总结,持续更新中,,,

1,从父视图删除所有子视图

  1. [xxxView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];  


2,图片旋转控制:

  1. #pragma mark ----- 更新按钮动画  
  2. - (void)rotate360DegreeWithImageViews:(UIImageView *)myViews{  
  3.     CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];  
  4.     rotationAnimation.toValue = [NSNumber numberWithFloatM_PI * 2.0 ];  
  5.     rotationAnimation.duration = 1.0;  
  6.     rotationAnimation.cumulative = YES;rotate360DegreeWithImageViews  
  7.     rotationAnimation.repeatCount = 100000;  
  8.     [myViews.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];  
  9. }  
  10. [myViews.layer removeAllAnimations]; // 停止  

3,添加一个铺满屏幕的UIView(比如在有UIN avigation,UIToolbar时不能全屏显示

     [[UIapplication sharedApplication].keyWindow addSubview:waitingview]; 


4,给UINavigationBar添加背景色或者添加自定义的图片

     设置背景色

1 UIColor *itemcolor = [UIColor colorWithRed:100.0f/255.0f green:176.0f/255.0f blue:0.0f/255.0f alpha:0.3f];  
2 self.navigationController.navigationBar.tintColor = itemcolor;  

     设置自定义图片

      [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@" “]];


5,让屏幕一直保持唤醒状态不黑屏

     [[UIApplication sharedApplication] setIdleTimerDisabled:YES];  


6,图片模糊化处理

    

+(UIImage *)scale:(UIImage *)image toSize:(CGSize)size  
3 {  
4     UIGraphicsBeginImageContext(size);  
5     [image drawInRect:CGRectMake(0, 0, size.width, size.height)];  
6     UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();  
7     UIGraphicsEndImageContext();  
8     return scaledImage;  
9 }  


7,字符串大小写转换

   1 NSString *str = @"hellow word";  

 2 // 全部转换为大写  
 3 NSString *str1 = [str uppercaseStringWithLocale:[NSLocale currentLocale]];    
    
 6 // 单词首字母大写  
 7 NSString *str2 = [str1 capitalizedStringWithLocale:[NSLocale currentLocale]];  
   
10 // 转换为原型  
11 NSString *str3= [str3 lowercaseStringWithLocale:[NSLocale currentLocale]];  
 

8,隐藏状态栏

    1,设置

      

     2,代码设置 

      [[UIApplication sharedApplication]setStatusBarHidden:YES];//隐藏状态栏


9,根据字体和文字数量动态计算UILabel长度和大小

      1 NSString *theText = @"hellow";

   2 UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:14.0f]; 
   3 CGSize theStringSize = [theText sizeWithFont:font constrainedToSize:theLabel.frame.size
   4 lineBreakMode:theLabel.lineBreakMode]; 
   5 theLable.frame= CGRectMake(theLable.frame.origin.x,
   6 theLable.frame.origin.y,theStringSize.width,theStringSize.height);
   7 theLable.text= theText; 

10,颜色转变成图片

- (UIImage *)createImageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

11,app评分跳转
-(void)goToAppStore
{
    NSString *str = [NSString stringWithFormat:
                     @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",项目id];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

13.获取当前系统语言环境

NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defs objectForKey:@"AppleLanguages"];
NSString *preferredLang = [languages objectAtIndex:0];

14.计算字符串的高度
NSString *str = @"chuanzhang";
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *dicAtt = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15],NSFontAttributeName,paragraphStyle.copy,NSParagraphStyleAttributeName, nil];
NSAttributedString *attribute = [[NSAttributedString alloc]initWithString:str attributes:dicAtt];
CGRect frame = [attribute boundingRectWithSize:CGSizeMake(200, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil];

15.强行关闭app的方法

// 私有API
[[UIApplication sharedApplication] performSelector:@selector(terminateWithSuccess)];
// C语言方法
exit(0);


16.如何快速的查看一段代码的执行时间

#define TICK   NSDate *startTime = [NSDate date]
#define TOCK   NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])
// 在想要查看执行时间的代码的地方进行这么处理
TICK
//do your work here
TOCK


  17.tableViewCell上的button,点击获取所在row

 UITableViewCell *cell = (UITableViewCell *)[[btn superview] superview];
 NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];

       

  18.设置粘贴内容

 [UIPasteboard generalPasteboard].string = @"string";
 // 获取粘贴内容
  NSString *string = [UIPasteboard generalPasteboard].string;

  19.iPhone为了节省电力所以有一个自动休眠机制,如果想让我们的APP不自动进入休眠只需要设置 UIApplication的idleTimerDisabled 属性为 YES 即             可。(切勿滥用)

       示例:

   [UIApplication sharedApplication].idleTimerDisabled = YES;

   20.UIApplicationUserDidTakeScreenshotNotification通知,当用户截屏时触发

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenCapture)             name:UIApplicationUserDidTakeScreenshotNotification object:nil];
   - (void)screenCapture{
    // doSomething
   }



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值