IOS开发基础知识--碎片9
1:两种方法删除NSUserDefaults所有记录
- //方法一
- NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
- [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
- //方法二
- - (void)resetDefaults {
- NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
- NSDictionary * dict = [defs dictionaryRepresentation];
- for (id key in dict) {
- [defs removeObjectForKey:key];
- }
- [defs synchronize];
- }
2:设置全局navigation barbuttonitem
- #pragma mark 设置全局navigation barbuttonitem
- -(void)setNaviBarButtonItemImage:(NSString *)imageName andX:(NSInteger)x andY:(NSInteger)y andW:(NSInteger)w andH:(NSInteger)h andTitle:(NSString *)title andSel:(SEL)sel andLOrR:(NSString *)lOr andTitleColor:(UIColor *)color{
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame =CGRectMake(x,y,w,h);
- [btn setTitle:title forState:UIControlStateNormal];
- if (imageName.length== && title.length==) {
- } else if (imageName.length== && title.length!=) {
- [btn setBackgroundColor:[UIColor clearColor]];
- [btn setTitleColor:color forState:UIControlStateNormal];
- }else if(imageName.length!= && title.length==){
- UIImage *image = [UIImage imageNamed:imageName];
- [btn setImage:image forState:UIControlStateNormal];
- }else if(imageName.length!= && title.length!=){
- UIImage *image = [UIImage imageNamed:imageName];
- [btn setBackgroundImage:image forState:UIControlStateNormal];
- [btn setBackgroundColor:[UIColor clearColor]];
- [btn setTitleColor:color forState:UIControlStateNormal];
- }
- [btn addTarget: self action:sel forControlEvents: UIControlEventTouchUpInside];
- UIBarButtonItem *bBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
- if ([lOr isEqualToString:@"left"]) {
- [self.navigationItem setLeftBarButtonItem:bBtn];
- }else{
- [self.navigationItem setRightBarButtonItem:bBtn];
- }
- }
3:UITableView设置Section间距
- 在使用IOS的UITableView时,时常会用到它的UITableViewStyleGrouped分组多section属性。而默认的情况下使用该属性后section之间的间距会比较大,看着很不舒服。那么可以通过以下的代理方法配置UITableView各个section的间距。
- 原理其实很简单,显示效果的各个section间距其实是section头部和底部的组合。配置他们的间距就是配置各个section的头部和底部
- //section头部间距
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return ;//section头部高度
- }
- //section头部视图
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView *view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
- view.backgroundColor = [UIColor clearColor];
- return [view autorelease];
- }
- //section底部间距
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return ;
- }
- //section底部视图
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- UIView *view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
- view.backgroundColor = [UIColor clearColor];
- return [view autorelease];
- }
4:解决OBJC_CLASS_$_MBProgressHUD无法引用的问题
- 虽然用POD把相关文件已经更新下来,但它却没有引入到工程中,要手动对它进行引用(或者直接放弃pod管理此插件,直接引入工程项目源代码中)
- Undefined symbols for architecture i386:
- "_OBJC_CLASS_$_MBProgressHUD", referenced from:
- objc-class-ref in ViewController.o
- ld: symbol(s) not found for architecture i386
- clang: error: linker command failed with exit code (use -v to see invocation)
- 这里的错误是因为你的在building phases中没有引用相关的头文件,因此,只需要在building phase中添加对应的.m文件就可以了。
5:iOS7 下使用SVPullToRefresh 下拉刷新导航栏位置错误
- iOS7 下使用SVPullToRefresh 下拉刷新导航栏位置错误;下拉刷新之后,tableview的第一列会跑到导航栏的下面;修正:添加如下代码
- /**
- * 下拉刷新 增加一个;
- */
- //修复下拉刷新位置错误 代码开始
- if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
- self.automaticallyAdjustsScrollViewInsets = NO;
- UIEdgeInsets insets = self.tableView.contentInset;
- insets.top = self.navigationController.navigationBar.bounds.size.height +
- [UIApplication sharedApplication].statusBarFrame.size.height;
- self.tableView.contentInset = insets;
- self.tableView.scrollIndicatorInsets = insets;
- }
- //修复下拉刷新位置错误 代码结束
- __block RootViewController *bSelf = self;
- [self.tableView addPullToRefreshWithActionHandler:^{
- [bSelf addRows];
- }];
- /**
- * 拉到最后 加载更多,增加一个;
- */
- [self.tableView addInfiniteScrollingWithActionHandler:^{
- [bSelf addMoreRow];
- }];
6:当改动布局要更新效果时
- CGRect headFrame=self.headerView.frame;
- headFrame.size.height=;
- self.headerView.frame = headFrame;
- [self.headerView setNeedsLayout];
- [self.headerView layoutIfNeeded];
7:给UITextField增加一个右边内的图片按键(rightView)
- UIButton *addCommentBtn=[[UIButton alloc]initWithFrame:CGRectMake(, , ,inputTextViewHeight)];
- [addCommentBtn setImage:[UIImage imageNamed:@"textViewEditNormal"] forState:UIControlStateNormal];
- [addCommentBtn addTarget:self action:@selector(addCommentAction) forControlEvents:UIControlEventTouchUpInside];
- _inputTextView.rightView=addCommentBtn;
- _inputTextView.rightViewMode=UITextFieldViewModeAlways;
8:NSLog 输出格式集合
- • %@ 对象
- • %d, %i 整数
- • %u 无符整形
- • %f 浮点/双字
- • %x, %X 二进制整数
- • %o 八进制整数
- • %zu size_t
- • %p 指针
- • %e 浮点/双字 (科学计算)
- • %g 浮点/双字
- • %s C 字符串
- • %.*s Pascal字符串
- • %c 字符
- • %C unichar
- • %lld 64位长整数(long long)
- • %llu 无符64位长整数
- %Lf 64位双字
9:设置UIImage的渲染模式:UIImage.renderingMode
- 设置UIImage的渲染模式:UIImage.renderingMode
- 着色(Tint Color)是iOS7界面中的一个.设置UIImage的渲染模式:UIImage.renderingMode重大改变,你可以设置一个UIImage在渲染时是否使用当前视图的Tint Color。UIImage新增了一个只读属性:renderingMode,对应的还有一个新增方法:imageWithRenderingMode:,它使用UIImageRenderingMode枚举值来设置图片的renderingMode属性。该枚举中包含下列值:
- UIImageRenderingModeAutomatic // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。
- UIImageRenderingModeAlwaysOriginal // 始终绘制图片原始状态,不使用Tint Color。
- UIImageRenderingModeAlwaysTemplate // 始终根据Tint Color绘制图片,忽略图片的颜色信息。
- renderingMode属性的默认值是UIImageRenderingModeAutomatic,即UIImage是否使用Tint Color取决于它显示的位置。
- UIImage *img = [UIImage imageNamed:@ "myimage" ]; img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
- 使用场景(Toolbar中增加item,item使用背景图,会出现色调为蓝色,如果要为图片原来的色调,则要修改图片的渲染,因为目前是渲染成文字的色调):
- @property (weak, nonatomic) IBOutlet UIBarButtonItem *mycollectionItem;
- UIImage *collectionItemImage=[UIImage imageNamed:@"bottomCollectionNormal"];
- collectionItemImage=[collectionItemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- self.mycollectionItem.image=collectionItemImage;
10:navigationController当前页隐藏后跳转回去页同样被隐藏
- 当前页隐藏代码:
- [self.navigationController setNavigationBarHidden:YES];
- 跳转时:
- [self.navigationController setNavigationBarHidden:NO];
- [self.navigationController popViewControllerAnimated:YES];
IOS开发基础知识--碎片9的更多相关文章
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- IOS开发基础知识--碎片33
1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...
- IOS开发基础知识--碎片42
1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...
- IOS开发基础知识--碎片50
1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...
- IOS开发基础知识--碎片3
十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...
- IOS开发基础知识--碎片11
1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...
- IOS开发基础知识--碎片14
1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识--碎片19
1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...
- IOS开发基础知识--碎片40
1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...
随机推荐
- SqlServer时间戳与普通格式的转换
/********************************************** 时间戳转换(秒) ******************************************* ...
- php这是一个随机打印输出字符串的例子
<?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); define(& ...
- android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画
ViewAnimationUtils.createCircularReveal()的简介: ViewAnimationUtils.createCircularReveal()是安卓5.0才引入的,快速 ...
- C++ 与 php 的交互 之----- C++ 异步获取 网页文字内容,异步获取 php 的 echo 值。
已搬迁至 http://www.cnblogs.com/linguanh/p/4543836.html
- Linux服务器(Ubuntu14.04)添加远程连接VNC Server
1.打开终端输入:sudo apt-get install xrdp, 2. sudo apt-get install vnc4server , 3. sudo apt-get install ...
- git安装和初次使用
为了知道某人安装git,我也是重装啊. 1.下载git并安装 2.打开我的电脑,右键属性,选择高级设置,打开环境变量设置: 3.键盘输入窗口键+r,或者点击开始->运行 输入cmd 在新打开的命 ...
- Linux 学习笔记
Linux学习笔记 请切换web视图查看,表格比较大,方法:视图>>web板式视图 博客园不能粘贴图片吗 http://wenku.baidu.com/view/bda1c3067fd53 ...
- react入门(1)
这篇文章也不能算教程咯,就算是自己学习整理的笔记把. 关于react一些相关的简介.优势之类的,随便百度一下一大堆,我就不多说了,可以去官网(http://reactjs.cn/)看一下. 这片主要讲 ...
- [WCF编程]11.错误:错误契约
一.错误传播 服务需要向客户端报告特定错误,当WCF默认的错误屏蔽方法并不包含这一实现.另一个重要的问题与传播到客户端有关,即由于异常是针对特定技术的,因此无法跨越服务边界而被共享.要实现无缝的互操作 ...
- Linux查看CPU和内存使用情况(转)
在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 top 命令后,CPU 使用状态会 ...