iOS-Development-Tips-1

独奏

技术分享|2014-12-29|最后更新: 2023-2-23|
type
Post
status
Published
date
Dec 29, 2014
slug
summary
tags
category
技术分享
icon
password

清除UITableView底部多余的分割线

self.tableView.tableFooterView = [[UIView alloc] init];

tableview 设置 cell 间的分割线长度

_myTableView.separatorInset = UIEdgeInsetsMake(0, 3, 0, 11);

把tableview里cell的小对勾的颜色改成别的颜色

_mTableView.tintColor = [UIColor redColor];

tableview里cell右侧小箭头

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //剪头前面添加文字 cell.detailTextLabel.text = @"mona";

计算ScrollView contentSize的通用方法

CGRect contentRect = CGRectZero; for (UIView *view in scrollView.subviews){ contentRect = CGRectUnion(contentRect, view.frame); } scrollView.contentSize = contentRect.size;

手势共存

// 单击的 Recognizer UITapGestureRecognizer *singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSingleTapFrom)]; singleRecognizer.numberOfTapsRequired = 1; // 单击 [self.view addGestureRecognizer:singleRecognizer]; // 双击的 Recognizer UITapGestureRecognizer* doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleDoubleTapFrom)]; doubleRecognizer.numberOfTapsRequired = 2; // 双击 [self.view addGestureRecognizer:doubleRecognizer]; // 关键在这一行,如果双击确定偵測失败才會触发单击 [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];

imageNamed的内存问题

通过这个方法得到的UIImage是一直缓存在内存中,直到程序结束为止。所有用IB在xib文件内设置图像的方法都是调用imageNamed这个方法,也就是说:这些内存在程序结束之前是一直保留着的,对于某些比较吃内存的应用就需要好好规划一下了。 UITableViewCell这种需要重用的控件就很适合使用imageNamed加载。
如果不需要图片资源一直存在内存,可以使用下面方法:
NSString *path = [[NSBundle mainBundle] pathForResource:@”icon” ofType:@”png”]; myImage = [UIImage imageWithContentsOfFile:path];

用户输入的情况下键盘事件处理繁琐

推荐一个三方库,很好的解决了键盘事件问题: IQKeyboardManager

点击任意位置收起键盘

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; }

像safari一样滑动的时候隐藏navigationbar

navigationController.hidesBarsOnSwipe = Yes

导航条返回键带的title太讨厌了,怎么让它消失

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

设置导航条title颜色

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor],UITextAttributeTextColor, [UIColor blackColor], UITextAttributeTextShadowColor, [UIFont fontWithName:CHINESE_FONT_NAME size:20.0f],UITextAttributeFont, [NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil]; // 修改单个 [self.navigationController.navigationBar setTitleTextAttributes:navbarTitleTextAttributes]; //修改全局 [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

CollectionView 实现tableview那种悬停的header

参考