部分知识点记录(一)
2017-09-21 本文已影响3人
JimmyL
判断两个数组是否相等,顺序不考虑
- (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