一、AFNetworking POST纯字符串
修改位置AFURLRequestSerialization
修改前
Nsstring * AFQueryStringFromParameters(NSDictionary *parameters) { NSMutableArray *mutablePairs = [NSMutableArray array]; for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) { [mutablePairs addobject:[pair URLEncodedStringValue]]; } return [mutablePairs componentsJoinedByString:@"&"]; }
修改后
Nsstring * AFQueryStringFromParameters(NSDictionary *parameters) { if ([parameters isKindOfClass:[Nsstring class]]) return (Nsstring *)parameters; NSMutableArray *mutablePairs = [NSMutableArray array]; for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) { [mutablePairs addobject:[pair URLEncodedStringValue]]; } return [mutablePairs componentsJoinedByString:@"&"]; }
二、查找一个字符串中的多个相同子字符串
Nsstring *str = @"14 28 62 24 3 46 99 73 10 51 0 95 34 58 50 33 56 23 97 82 83 8 94 1 17 7 19 96 9 54"; Nsstring *searchString = @"1"; NSRange searchRange = NSMakeRange(0, [str length]); NSRange range; while ((range = [str rangeOfString:searchString options:0 range:searchRange]).location != NSNotFound) { NSLog(@"%@",NsstringFromrange(range)); searchRange = NSMakeRange(NSMaxrange(range), [str length] - NSMaxrange(range)); }
三、UITextField限制字数
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(Nsstring *)string { NSInteger existedLength = textField.text.length; NSInteger selectedLength = range.length; NSInteger replaceLength = string.length; if (existedLength - selectedLength + replaceLength > 4) return NO; return YES; }
四、枚举数组元素
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { }];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNamed:@"image"]; attachment.bounds = CGRectMake(0, 0, 15, 15); NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init]; [string appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]]; [string appendAttributedString:[[NSAttributedString alloc] initWithString:@"string"]]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 30)]; label.attributedText = string; [self.view addSubview:label];
六、自适应屏幕大小
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
七、判断推送是否打开
BOOL registered = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
八、UIView转UIImage
- (UIImage *)viewToImage:(UIView *)view { UIImage *image = [[UIImage alloc] init]; UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, [UIScreen mainScreen].scale);// 区域 透明 屏幕密度 [view.layer renderInContext:UIGraphicsGetCurrentContext()]; image = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); return image; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。