美文网首页
部分知识点记录(一)

部分知识点记录(一)

作者: JimmyL | 来源:发表于2017-09-21 11:21 被阅读3次

判断两个数组是否相等,顺序不考虑

- (BOOL)isTwoArrayEqualWithOneArray:(NSArray *)oneArray otherArray:(NSArray *)otherArray {
    NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"NOT (SELF IN %@)", oneArray];
    NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"NOT (SELF IN %@)", otherArray];
    if (([otherArray filteredArrayUsingPredicate:predicate1].count > 0) || ([oneArray filteredArrayUsingPredicate:predicate2].count > 0)) {
        return NO;
    }
    return YES;
}

为UIView添加虚线框

- (void)addBorder {
    CAShapeLayer *borderLayer = [CAShapeLayer layer];
    borderLayer.bounds = self.bounds;
    borderLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
    borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:2.0].CGPath;
    borderLayer.lineWidth = 0.5;
    //虚线边框
    borderLayer.lineDashPattern = @[@8, @4];
    borderLayer.fillColor = [UIColor clearColor].CGColor;
    borderLayer.strokeColor = SAColorByRGB(220, 220, 220).CGColor;
    [self.layer addSublayer:borderLayer];
}

截图

- (UIImage *)imageForCutScreen{
    UIGraphicsBeginImageContext(self.frame.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}

runtime打印属性、变量

    typedef struct objc_ivar *Ivar;
    unsigned int count;
    Ivar *ivars = class_copyIvarList([UIPickerView class], &count);
    for (int i = 0; i < count; i++) {
        const char *ivarName = ivar_getName(ivars[i]);
        NSString *str = [NSString stringWithCString:ivarName encoding:NSUTF8StringEncoding];
        NSLog(@"ivarName : %@", str);
    }
    
    unsigned int count;
    objc_property_t *properties = class_copyPropertyList([UIView class], &count);
    for (int i = 0; i < count; i++) {
        const char *propertiesName = property_getName(properties[i]);
        NSString *str = [NSString stringWithCString:propertiesName encoding:NSUTF8StringEncoding];
        NSLog(@"propertyName : %@", str);
    }

改变图标颜色

//写在UIImage的类别中的
- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode {
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
    [tintColor setFill];
    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
    UIRectFill(bounds);
    
    [self drawInRect:bounds blendMode:blendMode alpha:1.0f];
    
    if (blendMode != kCGBlendModeDestinationIn) {
        [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
    }
    
    UIImage *tintImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return tintImage;
}

获取当前控制器

- (UIViewController*)topMostController
{
    UIViewController *topController = [self rootViewController];
    
    //  Getting topMost ViewController
    while ([topController presentedViewController]) topController = [topController presentedViewController];
    
    //  Returning topMost ViewController
    return topController;
}

- (UIViewController*)currentViewController;
{
    UIViewController *currentViewController = [self topMostController];
    
    while ([currentViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)currentViewController topViewController])
        currentViewController = [(UINavigationController*)currentViewController topViewController];
    
    return currentViewController;
}

UITextField关闭系统自动联想和首字母大写功能

//clearBUtton偏移
[_textField setValue:[NSValue valueWithCGPoint:CGPointMake(-10 - 15*kSACardWidthRatio(), 0)] forKeyPath:@"_clearButtonOffset"];
//不联想
[_txtField setAutocorrectionType:UITextAutocorrectionTypeNo];
//首字母不大写
[_txtField setAutocapitalizationType:UITextAutocapitalizationTypeNone];

textField clearButton图片替换

- (void)changeClearButtonTintImageWithTextField:(UITextField *)textField {
    UIButton *clearButton = (UIButton *)[textField valueForKey:@"_clearButton"];
    [clearButton setImage:[UIImage imageNamed:@"clearButton"] forState:UIControlStateNormal];
    [clearButton setImage:[UIImage imageNamed:@"clearButton"] forState:UIControlStateHighlighted];
}

xcode 修改类名

打开类的 .h 文件,将光标移至类名处右键 Refactor -> Rename:


Refactor -> Rename.png

出现如下界面,编辑名称点击 Rename 即可:


Rename.png

相关文章

  • 部分知识点记录(一)

    判断两个数组是否相等,顺序不考虑 为UIView添加虚线框 截图 runtime打印属性、变量 改变图标颜色 获取...

  • iOS 题目详解 部分一

    主要记录一些题目所关联的知识点, 详解 iOS 题目详解 部分一iOS 题目详解 部分二iOS 题目详解 部...

  • iOS 题目简述 部分一

    主要记录一些题目所关联的知识点, 简单概述 iOS 题目详解 部分一iOS 题目详解 部分二iOS 题目详解...

  • 5个记笔记重要点

    ①记知识点的框架 先听老师讲,然后记录老师的纲要部分和重点部分,这样可以将知识体系一目了然。 ②记思维 记录老师推...

  • (十一)async和await

    本节知识点 async await 知识点async 基础部分 高级部分

  • 01/22

    果然从小到大,考试都会忘记一些知识点,总是不能完全记录下知识点,啊啊啊 似乎说到考试都会很害怕,虽然大部分都会,但...

  • iOS笔记篇-熟悉OC<一>

    前言 该部分篇章,将会比较碎。主要用于记录自己开发和书籍中看到比较有价值的知识点的记录和归纳。 Objective...

  • 2019-05-29

    小潘曾在增值税(一)中有记录过这部分的内容,当时对于这部分知识点一直处于“看山是山的‘’的状态;今天决定试着以“看...

  • 部分知识点

    chr(编码值) - 将字符编码转换成字符 ord(字符) - 获取字符对应的编码值 可以将字符编码放到字符串中便...

  • 部分记录

    courses_ML16.2018-03-23 courses_ML16\ 1. ML Lecture 1: Re...

网友评论

      本文标题:部分知识点记录(一)

      本文链接:https://www.haomeiwen.com/subject/hchssxtx.html