iOS 开发小技巧
来源:互联网 发布:温度监控软件 编辑:程序博客网 时间:2024/06/01 20:58
UI
自定义了leftBarbuttonItem左滑返回手势失效了怎么办?
方式一
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(onBack:)];self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
方式二
在编辑 Tableview 的过程中 (如 tableview 正在执行删除 cell 的动画),这个时候返回 NavigationController 的上一级,就会导致左划返回手势失败。这个时候可以在 动画完成后再返回或者动画过程中不允许返回
[CATransaction begin];[self.tableView beginUpdates];[self.tableView deleteRowsAtIndexPaths:@[_deleteIndexPath] withRowAnimation:UITableViewRowAnimationLeft];[CATransaction setCompletionBlock: ^{ [self.navigationController.navigationBar setUserInteractionEnabled:YES];}];[self.tableView endUpdates];[CATransaction commit];
ScrollView莫名其妙不能在viewController划到顶怎么办?
self.automaticallyAdjustsScrollViewInsets = NO;
键盘事件写的好烦躁,都想摔键盘了,怎么办?
1.买个结实的键盘.
2.使用IQKeyboardManager(github上可搜索),用完之后腰也不疼了,腿也不酸了.
怎么在不新建一个Cell的情况下调整separaLine的位置?
_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);
怎么像safari一样滑动的时候隐藏navigationbar?
navigationController.hidesBarsOnSwipe = YES;
导航条返回键带的title太讨厌了,怎么让它消失!
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
CollectionView 怎么实现tableview那种悬停的header?
CSStickyHeaderFlowLayou
怎么播放GIF的时候这么卡,有没有好点的库?
FlipBoard出品的太适合你了
https://github.com/Flipboard/FLAnimatedImage
YLGIFImage
https://github.com/liyong03/YLGIFImage
怎么把tableview里cell的小对勾的颜色改成别的颜色?
_mTableView.tintColor = [UIColor redColor];
本来我的statusbar是lightcontent的,结果用UIImagePickerController会导致我的statusbar的样式变成黑色,怎么办?
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];}
怎么把我的navigationbar弄成透明的而不是带模糊的效果?
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];self.navigationBar.shadowImage = [UIImage new];self.navigationBar.translucent = YES;
怎么改变uitextfield placeholder的颜色和位置?
// 继承uitextfield,重写这个方法- (void) drawPlaceholderInRect:(CGRect)rect { [[UIColor blueColor] setFill]; [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];}
怎样在 UITextView 中显示 HTML 格式的文本
NSString *htmlString = @"<p><strong>自定义了leftBarbuttonItem左滑返回手势失效了怎么办?</strong></p>"; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil]; self.result.attributedText = attributedString;
字符串全角和半角转换
NSString *string = @"hehe"; NSMutableString *convertedString = [string mutableCopy]; // 半角转全角只需要把 kCFStringTransformFullwidthHalfwidth 换成kCFStringTransformHiraganaKatakana 即可。CFStringTransform((CFMutableStringRef)convertedString, NULL, kCFStringTransformFullwidthHalfwidth, false); NSLong(@"ddc:%@",convertString);
ipa 解包后看不到 png 资源怎么办
当 Xcode 打包时会使用自带的图片压缩工具 pngcrush 压缩 png 图片。如果解包后发现部分 png 图片不能查看,可以使用下面的命令来解压缩图片 pngcrush -revert-iphone-optimizations src des
下面是唐巧大神在《iOS 开发进阶》中提供的一段脚本
#!/bin/bashmkdir OriginImagesfor png in `find . -name '*.png'`do name=`basename $png` pngcrush -revert-iphone-optimizations $name OriginImages/$namedone
Objective-C
对象下标(像数组或字典一样访问对象数据)
参考文章
- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
在头文件声明上面两个方法,并在 .m 中实现,就可以实现类似 C 语言数组访问数据的方式来访问自定义对象的数据
如:
SubscriptTestObject *object = [[SubscriptTestObject alloc] init]; id aa = object[10];object[11] = @"12";
在头文件声明下面两个方法,并在 .m 中实现,就可以实现 dic[@"key"] = @"value"
方式来访问和修改自定义对象的数据
- (id)objectForKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
如:
SubscriptTestObject *object = [[SubscriptTestObject alloc] init];id aa = object[@"key"];object[@"key01"] = @"12345";[object setObject:@"value" forKeyedSubscript:@"key02"];
参考文章
《iOS开发的一些奇巧淫技》
0 0
- iOS开发 小技巧
- iOS 开发小技巧
- ios开发小技巧
- ios开发小技巧
- iOS 开发小技巧
- IOS 开发小技巧
- iOS开发小技巧
- ios开发小技巧
- iOS开发小技巧
- iOS 开发小技巧
- iOS 开发小技巧
- iOS 开发小技巧
- ios开发小技巧
- ios 开发小技巧
- ios开发小技巧
- iOS 开发小技巧
- IOS开发小技巧
- iOS 开发小技巧
- 通用数组长度的获取
- java.lang.NoClassDefFoundError
- 推荐五个非常实用的软件---(编辑器和日常)
- IndentationError:expected an indented block错误解决
- ajax post中文乱码问题
- iOS 开发小技巧
- 正益移动王国春当选“2015中国互联网+最具创新力年度人物”
- 实施针对 TLS_FALLBACK_SCSV 的支持。禁用 SSLv3 支持
- 她是张作霖钦定的儿媳 但张学良最终没选择她
- Python第二讲基本数据类型
- 安卓onkeyup onkeydown事件小记
- 2015年终总结,细细的数曾经走过的路
- iOS每日一记————————CoreText初识
- Android原生下拉刷新SwipeRefreshLayout