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 ...
随机推荐
- python-水仙花数
>>> for a in range(1,10):... for b in range(0,10):... for c in range(0,10):... x=100*a+10*b ...
- swift详解之九---------------自动引用计数、循环引用
自动引用计数.循环引用(这个必须理解,必须看) 注:本文详细介绍自动引用计数,以及各种循环引用问题.一网打尽! 1. 自动引用计数原理 Swift 使用ARC机制来跟踪和管理你的内存,一般情况下,Sw ...
- 【详●析】[GXOI/GZOI2019]逼死强迫症
[详●析][GXOI/GZOI2019]逼死强迫症 脑子不够用了... [题目大意] 在\(2\times N\)的方格中用\(N-1\)块\(2\times 1\)的方砖和\(2\)块\(1\tim ...
- kafka 理论学习
http://blog.csdn.net/paul342/article/details/50479491 kafka基本知识.
- 完善的IaaS云服务的个人理解
此文已由作者王盼授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 前情提要 本文仅讨论云主机(虚拟机).云硬盘(块存储).云网络(普通虚拟网络或SDN)相关的IaaS服务,相关 ...
- Mac 10.10 配置apache
配置php 命令行工具:http://blog.csdn.net/evane1890/article/details/38759073 自从系统从OS X Mavericks 10.9升级到OS X ...
- Python MySQLdb 查询中文出现问号的解决方法
在连接数据库的时候设置如下即可: db = MySQLdb.connect('localhost','root','×××××','test',use_unicode=True,charset=&qu ...
- zoj 2818 Root of the Problem
Root of the Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Given positive integers B and ...
- codeforces #301 div2
A:简单题 每次判断向上转快,还是向下转快即可 #include <cstdio> #include <cstring> #include <iostream> # ...
- bzoj2277 [Poi2011]Strongbox
2277: [Poi2011]Strongbox Time Limit: 60 Sec Memory Limit: 32 MBSubmit: 498 Solved: 218[Submit][Sta ...