标签:
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==0 && title.length==0) {
} else if (imageName.length==0 && title.length!=0) {
[btn setBackgroundColor:[UIColor clearColor]];
[btn setTitleColor:color forState:UIControlStateNormal];
}else if(imageName.length!=0 && title.length==0){
UIImage *image = [UIImage imageNamed:imageName];
[btn setImage:image forState:UIControlStateNormal];
}else if(imageName.length!=0 && title.length!=0){
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 1;//section头部高度
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
view.backgroundColor = [UIColor clearColor];
return [view autorelease];
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
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 1 (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=200; self.headerView.frame = headFrame; [self.headerView setNeedsLayout]; [self.headerView layoutIfNeeded];
7:给UITextField增加一个右边内的图片按键(rightView)
UIButton *addCommentBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40,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属性。该枚举中包含下列值:
1 UIImageRenderingModeAutomatic // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。
2 UIImageRenderingModeAlwaysOriginal // 始终绘制图片原始状态,不使用Tint Color。
3 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];
标签:
原文地址:http://www.cnblogs.com/LiLihongqiang/p/5790534.html