iOS记录一常用的方法和语句

5、解析UIColor的R,G,B的值

- (void)getRGBDictionaryByColor:(UIColor *)originColor
{
    CGFloat R = 0, G = 0, B = 0, A = 0;
    if ([self respondsToSelector:@selector(getRed:green:blue:alpha:)])
    {
        [originColor getRed:&R green:&G blue:&B alpha:&A];
    }else
    {
        const CGFloat *components = CGColorGetComponents(originColor.CGColor);
        R = components[0] * 255;
        G = components[1] * 255;
        B = components[2] * 255;
        A = components[3] * 100;
    }
    NSLog(@"R = %.f,%.f,%.f,%.2f",R,G,B,A);
}

 

 

 

4、获取启动页图片名

- (NSString *)getLaunchImageName
{
    NSString *viewOrientation = @"Portrait";
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
    {
        viewOrientation = @"Landscape";
    }
    NSString *launchImageName = nil;
    NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    CGSize viewSize = [UIScreen mainScreen].bounds.size;
    for (NSDictionary* dict in imagesDict)
    {
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]])
        {
            launchImageName = dict[@"UILaunchImageName"];
        }
    }
    return launchImageName;
}

 

 

3、延迟执行

//延迟执行
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(0.5* NSEC_PER_SEC)),dispatch_get_main_queue(),^{
    [self PandaInitParmsView];
});

 

1、当前控制器是否还显示,比较常用于网络请求回来页面已退出

//当前视图控制器是否在显示
+(BOOL)isCurrentViewControllerVisible:(UIViewController *)viewController
{
    return (viewController.isViewLoaded && viewController.view.window);
}

 

2、获取plist数据

    //1. 从文件中读取plist文件的路径
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Question" ofType:@"plist"];
    //2、从文件路径获取数据
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

 

posted @ 2017-08-02 09:06  wq95230  阅读(256)  评论(0编辑  收藏  举报