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 ...
随机推荐
- layui使用小记(持续更新)
关于Select等Form表单元素,在使用的时候部分特性会失效 如select自带的Search功能: 其实在使用Form表单元素的时候,你如果需要layui自带的一些功能(搜索,验证等),请用< ...
- 7. 配置undo表空间
7. 配置undo表空间 undo日志可以存储在一个或多个undo表空间中,无需存储在系统表空间中. 要为MySQL实例配置单独的undo表空间,请执行以下步骤 [重要]: 只能在初始化新MySQL实 ...
- 第一章:systemverilog简介
1.为何要学systemverilog ..... 2.systemverilog起源 ..... 3.systemverilog标准历程 systemverilog3.0 for 综合 system ...
- Root of AVL Tree
04-树5 Root of AVL Tree(25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, the ...
- [BZOJ 3823]定情信物
题面 定情信物 题解 这题主要考高中物理和数学. 首先定义 \(f[i][j]\) 表示 \(i\) 维超立方体中第 \(j\) 维元素的数量,根据实际意义,我们可以推出递推式: \(f[i][j]= ...
- 【shell】文本处理的一些小技巧
一.Shell 二.Sed 三.Awk
- 大数据学习——linux常用命令(二)四
系统管理操作 1 挂载外部存储设备 可以挂载光盘.硬盘.磁带.光盘镜像文件等 1/ 挂载光驱 mkdir /mnt/cdrom 创建一个目录,用来挂载 mount -t iso9660 ...
- Idea中配置svn时报 Can't use Subversion command line client: svn.Errors found while svn working copies detection.
https://www.cnblogs.com/wqh17/p/6881483.html
- 什么是Istio
本文主要是对Istio Prelim 1.0(https://preliminary.istio.io/docs/)的翻译 Istio:一种开放式平台,用于连接,管理和保护微服务. Istio提供了一 ...
- 日志不得应用情况切换强制standby改变状态为primary
日志不得应用情况切换备库为主库 备库运行如下: alter database recover managed standby database disconnect from session; alt ...