iOS 开发小常识 开发笔记
一 自定义push方法
/* 参数说明
* controllerName : push的目标页 例:@“testcontroll” ---注意不带.h
* isNibPage : 目标页是否带 xib 文件
* setHideTabBar : 当前页是否隐藏 tabBar -----注意 是当前页 非目标页
* setDelegate : 设置委托
*/
- (void)pushNewViewController:(NSString *)controllerName isNibPage:(BOOL) _isNib setHideTabBar:(BOOL) _bool setDelegate:(BOOL) _setdelegate{
if (controllerName.length <= 0) {
return;
}
Class class_Page = NSClassFromString((NSString *)controllerName);
id viewCtrl_Page = _isNib ? [[class_Page alloc] initWithNibName:controllerName bundle:nil]
: [[class_Page alloc] init];
if (_setdelegate) { [viewCtrl_Page setDelegate:self]; }
if (!m_Params) { m_Params = [[NSMutableDictionaryalloc]init]; }
[m_Params setValue:_bool == YES ? @"1" : @"0" forKey:@"HideTabBar"];
[viewCtrl_Page setM_Params:[m_Params retain]];
if (isLoginPage) {
if ([GlobalisUserLogin]) {
[self.navigationControllerpushViewController:viewCtrl_Page animated:YES];
}
else{
[selfshowLoginController];
}
}
else
[self.navigationControllerpushViewController:viewCtrl_Page animated:YES];
[viewCtrl_Page release];
if (m_Params) {
[m_Params release];
}
}
二 根据TableView里的button获取父级UITableViewCell
1. 通过对像的父级查找
UIButton *btn_checkBox = (UIButton *)sender;
UITableViewCell * cell = (UITableViewCell *)[btn_checkBox superview];
NSIndexPath* indexPath = [m_tableViewindexPathForCell:cell];
2. 通过点击座标
// 检查用户点击按钮时的位置,并转发事件到对应的accessory tapped事件
- (void)btnClicked:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:currentTouchPosition];
if(indexPath != nil)
{
[self tableView:self.tableView accessoryButtonTappedForRowWithIndexPath:indexPath];
}
}
三 常常要算一段文字的长度和高度。下面这段代码可以帮到你
CGSize fontsize = [tmpCoupon.couponDescsizeWithFont:[UIFontboldSystemFontOfSize:13] constrainedToSize:CGSizeMake(162, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
// 计算文本的大小 ios7.0
CGSize textSize = [textViewTemple.text boundingRectWithSize:CGSizeMake(self.imagewidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading // 文本绘制时的附加选项
attributes:dic context:nil].size;
四 文本编辑的时候键盘档住页面,下面代码自动收缩
- (void)textFieldDidBeginEditing:(UITextField *)textField{
CGRect frame = textField.frame;
int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0-10);
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationDuration:animationDuration];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
if(offset > 0){
CGRect rect = CGRectMake(0.0f, -offset,width,height);
self.view.frame = rect;
}
[UIView commitAnimations];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);
self.view.frame = rect;
[UIView commitAnimations];
[textField resignFirstResponder];
return YES;
}
// 十六进制设置alpha值
+ (UIColor *)convertHexToRGB:(NSString *)hexString alpha:(CGFloat)alpha {
NSString *str;
if ([hexString hasPrefix:@"0x"] || [hexString hasPrefix:@"0X"]) {
str=[[NSString alloc] initWithFormat:@"%@",hexString];
}else {
str=[[NSString alloc] initWithFormat:@"0x%@",hexString];
}
int rgb;
sscanf([str cStringUsingEncoding:NSUTF8StringEncoding], "%i", &rgb);
[str release];
int red=rgb/(256*256)%256;
int green=rgb/256%256;
int blue=rgb%256;
UIColor *color=[UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha];
return color;
}
五 . 数组排序
NSSortDescriptor * sortDescriptor = [[NSSortDescriptoralloc] initWithKey:@"createTime"ascending:NO];
[arrMsgListsortUsingDescriptors:[NSArrayarrayWithObject:sortDescriptor]];
iOS 开发小常识 开发笔记的更多相关文章
- iOS AVCaptureSession 小视频开发总结,支持设备旋转
iOS开发中当我们想要自定义相机拍照或摄像界面时,UIImagePickerController无法满足我们的需求,这时候我们可以使用AVFoundation.framework这个framework ...
- Java 开发小常识
从理论上来讲Java做的系统并不比其他语言开发出来的系统更占用内存,那么为什么却有这么多理由来证明它确实占内存呢?两个字,陋习. 1.别用new Boolean().在很多场景中Boolean类型是必 ...
- 微信小程序开发详解——小程序,大颠覆!
微信小程序开发 联系 苏念 188.1414.7927 微信小程序系统开发 微信新功能开发 小程序开发 小程序怎么开发 app小程序开发 简化小程序开发 微信小程序定制 小程序制作 开发微信小程序 ...
- iOS开发小技巧 - UILabel添加中划线
iOS开发小技巧 遇到的问题: 给Label添加中划线,然后并没有效果 NSString *str = [NSString stringWithFormat:@"合计金额 ¥%.2f&quo ...
- iOS开发小技巧 - runtime适配字体
iOS开发小技巧 - runtime适配字体 版权声明:本文为博主原创文章,未经博主允许不得转载,有问题可联系博主Email: liuyongjiesail@icloud.com 一个iOS开发项目无 ...
- iOS学小程序从0到发布(适合iOS开发看)
Emmmm,最近一波失业潮.富某康.某团.摩某.京某.知某.某浪.58 某大面积裁员,那么在这个千钧一发之际,单纯iOS开发也着实不好过,回过头看一下,裁掉的都是单一选手,为了节约成本公司留下的都是身 ...
- 微信小程序开发:学习笔记[7]——理解小程序的宿主环境
微信小程序开发:学习笔记[7]——理解小程序的宿主环境 渲染层与逻辑层 小程序的运行环境分成渲染层和逻辑层. 程序构造器
- 微信小程序开发:学习笔记[5]——JavaScript脚本
微信小程序开发:学习笔记[5]——JavaScript脚本 快速开始 介绍 小程序的主要开发语言是 JavaScript ,开发者使用 JavaScript 来开发业务逻辑以及调用小程序的 API 来 ...
- 微信小程序开发:学习笔记[4]——样式布局
微信小程序开发:学习笔记[4]——样式布局 Flex布局 新的布局方式 在小程序开发中,我们需要考虑各种尺寸终端设备上的适配.在传统网页开发,我们用的是盒模型,通过display:inline | b ...
随机推荐
- 乘法逆元-洛谷-P3811
题目背景 这是一道模板题 题目描述 给定n,p求1~n中所有整数在模p意义下的乘法逆元. 输入输出格式 输入格式: 一行n,p 输出格式: n行,第i行表示i在模p意义下的逆元. 输入输出样例 输入样 ...
- linux批量检测服务器能否ping通和硬盘容量状态并抛出报警的一个脚本-附详细解释
有一些linux基础,最近刚开始学shell,参考了阿良老师的一个监测服务器硬盘状态的脚本,自己进行了一些扩展,今天比较晚了,后边会把注释放上来,感觉脚本还很不完善,希望大家一起探讨一下,共同学习 2 ...
- “打开ftp服务器上的文件夹时发生错误,请检查是否有权限访问该文件夹"
阿里云虚拟主机上传网站程序 问题场景:网页制作完成后,程序需上传至虚拟主机 注意事项: 1.Windows系统的主机请将全部网页文件直接上传到FTP根目录,即 / . 2. 如果网页文件较多,上传较慢 ...
- SpringBoot的线程调度
Spring Boot默认提供了一个ThreadPoolTaskExecutor作为线程调度器,只需要在配置类中使用注解EnableAsync即可开启异步线程调度.在实际要执行的Bean中使用@Asy ...
- phpstorm的全局操作快捷键ctrl+shift+f被搜狗占用处理方法
1.找到搜狗软件,右键选择属性设置 2.如图选择系统功能快捷键 3.去掉简繁切换快捷方式,确定后即可使用phpstorm的ctrl+shift+f来进行全局查找
- CentOS 7的docker安装初始化
1: 安装必要的一些系统工具 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 2: 添加软件源信息 添加阿里源这样下载 ...
- pycharm的快捷键以及常用设置
1.编辑(Editing) Ctrl + Space 基本的代码完成(类.方法.属性) Ctrl + Alt + Space 快速导入任意类 Ctrl + Shift + Enter 语句完成 Ctr ...
- 【C#】【数据结构】005-栈:顺序栈
C#数据结构:顺序栈 1.自定义顺序栈结构: /// <summary> /// 顺序栈 /// </summary> /// <typeparam name=" ...
- react 语法细节总结说明
1.当要获取某个数据列表中的某个字段时,用“.”附加的形式.例如:获取user中的balance字段,用this.props.user.balance 来表示. 2.当要打印某个数据或字段结果时,co ...
- HDU3785寻找大富翁~~真真切切的水题
寻找大富翁 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...