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 ...
随机推荐
- ios之AFN
https://github.com/AFNetworking/AFNetworking 与asi-http-request功能类似的网络库,不过是基于NSURLConnection 和 NSOper ...
- 生产环境屏蔽swagger(动态组装bean)
spring动态组装bean 背景介绍: 整合swagger时需要在生产环境中屏蔽掉swagger的地址,不能在生产环境使用 解决方案 使用动态profile在生产环境中不注入swagger的bean ...
- @ApiParam @RequestParam @PathVariable 用法
文章来源:https://www.cnblogs.com/hello-tl/p/9204279.html 1.@ApiParam ,是注解api的参数 ,也就是用于swagger提供开发者文档 ,文档 ...
- 《算法导论》— Chapter 6 堆排序
序 本文主要介绍堆排序算法(HeapSort),堆排序像合并排序而不像插入排序,堆排序的运行时间为O(nlgn):像插入排序而不像合并排序,它是一种原地(in place)排序算法.在任何时候,数组中 ...
- NOI模拟赛(3.15) sequence(序列)
Description 小A有N个正整数,紧接着,他打算依次在黑板上写下这N个数.对于每一个数,他可以决定将这个数写在当前数列的最左边或最右边.现在他想知道,他写下的数列的可能的最长严格上升子序列(可 ...
- BeautifulSoup4系列一
前言 以博客园为例,爬取我的博客上首页的发布时间.标题.摘要,本篇先小试牛刀,先了解下它的强大之处,后面讲beautifulsoup4的详细功能. 一.安装 1.打开cmd用pip在线安装beauti ...
- 72.spring boot讨论群【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 如果您碰到什么问题,您可以加群进行探讨,在群里有加入的都是Spring Boot志同道合的朋友: Spring Boot QQ交流群:193341 ...
- POJ 1379 (随机算法)模拟退火
题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...
- 【二分贪心+精度问题】F. Pie
https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/F [题意] 给定n个已知半径的披萨,有m个人要分这n个披萨 要求每个人分到的面积 ...
- 关于NSArray的去重
提到去重,第一反应就是for或while循环来遍历处理. 然后有了几种思路: 1) 两个循环嵌套 对比 然后去重: 但是这种方法会数据丢失, arr为要去重的数组 ; i<arr.count; ...