IOS11
label中划线设置 //中划线 NSMutableAttributedString *attribtStr_origin = [[NSMutableAttributedString alloc]initWithString:originalMoney attributes:attribtDic]; [attribtStr_origin setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle),NSForegroundColorAttributeName:[Toolkit getColor:hex_aaaaaa]} range:NSMakeRange(0,attribtStr_origin.length)]; [attribtStr_origin addAttribute:NSFontAttributeName value:[UIFont fontWithName:@'GillSans' size:12.0] range:NSMakeRange(0,attribtStr_origin.length)]; [attribtStr appendAttributedString:attribtStr_origin];
Mansonry不用弱引用 为什么不会循环引用-(NSArray )mas_makeConstraints:(void(^)(MASConstraintMaker ))block {self.translatesAutoresizingMaskIntoConstraints = NO;MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];block(constraintMaker);return [constraintMaker install];}这个就和网络请求里面使用self道理是一样的。因为UIView未强持有block,所以这个block只是个栈block,而且构不成循环引用的条件。栈block有个特性就是它执行完毕之后就出栈,出栈了就会被释放掉。看mas_makexxx的方法实现会发现这个block很快就被调用了,完事儿就出栈销毁,构不成循环引用,所以可以直接放心的使用self。masonry里面没有额外引用起来,block执行完之后就随着方法执行完之后就销毁了,不存在一直被引用释放不了的问题,所以无需weak。weak也无所谓。
跨多级页面跳转 [[_app_ getTabBar] selectTableBarIndex:2]; [self.navigationController popToRootViewControllerAnimated:NO]; UINavigationController *selectedNavi = [_app_ getTabBar].selectedViewController; if (selectedNavi.viewControllers.count >0) { if ([[selectedNavi.viewControllers firstObject] class] == [ProfileViewController class]) { PropertyDetailViewController *propertyDetailVC =[[PropertyDetailViewController alloc]initWithPropertyType:6]; ProfileViewController *ProfileViewController = [selectedNavi.viewControllers firstObject]; [ProfileViewController.navigationController pushViewController:propertyDetailVC animated:NO]; } }
键盘遮挡问题 手势冲突//解决手势冲突 网格点击- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ if (touch.view != self.customCollectionView) { [self.view endEditing:YES]; return NO; } return YES;}
键盘输入框限制输入等处理1.先加入事件 [_phoneTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];2.处理方法- (void)textFieldDidChange:(UITextField *)textField{ UITextRange *selectedRange = textField.markedTextRange; UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0]; if (!position) { // 没有高亮选择的字 // 1. 过滤非汉字、字母、数字字符 self.phoneTextField.text = [self filterCharactor:textField.text withRegex:@'[^0-9]']; // 2. 截取 if (self.phoneTextField.text.length >= 12) { self.phoneTextField.text = [self.phoneTextField.text substringToIndex:11]; } } else { // 有高亮选择的字 不做任何操作 }}// 过滤字符串中的非汉字、字母、数字- (NSString *)filterCharactor:(NSString *)string withRegex:(NSString *)regexStr{ NSString *filterText = string; NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error]; NSString *result = [regex stringByReplacingMatchesInString:filterText options:NSMatchingReportCompletion range:NSMakeRange(0, filterText.length) withTemplate:@'']; return result;}
oc中的泛型举例:- (void)test { NSMutableArray
修改UIAlertView设置文字左对齐因为iphoneSDK默认是居中对齐的,而且没有提供方法设置文本对齐接口,在Delegate中:- (void)willPresentAlertView:(UIAlertView *)alertView;获取UIAlertView上面的Message控件,它其实也是一个UILable控件,然后设置其textAlignment的属性即可。代码如下:- (void)willPresentAlertView:(UIAlertView *)alertView{ UIView * view = [alertView.subviews objectAtIndex:2]; if([view isKindOfClass:[UILabel class]]){ UILabel* label = (UILabel*) view; label.textAlignment = UITextAlignmentLeft; }}这里要注意的是,Message的UILable在alertView.subviews里面是第3个元素,第一个元素是一个UIImageView(背景),UILable(标题),UILable(Message),UIButton(Cancel)...(如果还有的话以此类推)。
iPhone6屏幕获取不准的原因手机设置在放大模式 会导致代码获取屏幕尺寸不准 6 6s 7 宽度和 5s 输出宽度一直 设置改为标准模式 消失CGRect bounds = [[UIScreen mainScreen] bounds]; NSString *screenMode = [[UIScreen mainScreen].coordinateSpace description]; CGFloat scale = [[UIScreen mainScreen] scale]; CGFloat nativeScale = [[UIScreen mainScreen] nativeScale]; NSLog(@' bounds: %@ screen mode: %@ scale: %f native scale: %f', NSStringFromCGRect(bounds), screenMode, scale, nativeScale);
本地字典写成需要的JSON 本地文件 // 1.判断当前对象是否能够转换成JSON数据. // YES if obj can be converted to JSON data, otherwise NO BOOL isYes = [NSJSONSerialization isValidJSONObject:dict]; if (isYes) { NSLog(@'可以转换'); /* JSON data for obj, or nil if an internal error occurs. The resulting data is a encoded in UTF-8. */ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL]; // 将JSON数据写成文件 // 文件添加后缀名: 告诉别人当前文件的类型. // 注意: AFN是通过文件类型来确定数据类型的!如果不添加类型,有可能识别不了! 自己最好添加文件类型. [jsonData writeToFile:@'/Users/ygkj/Desktop/shopCartTestData.json' atomically:YES]; NSLog(@'%@', [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]); } else { NSLog(@'JSON数据生成失败,请检查数据格式'); }
滚动试图不滚动的问题-(void)viewDidLayoutSubviews{ _BaseScore.contentSize = CGSizeMake(SCREEN_WIDTH, xxxx);}