
iOS开发笔记
iCHENKE
但行好事,莫问前程!
展开
-
iOS UILabel自适应高度
-(CGSize)sizeWithString:(NSString *)string font:(UIFont *)font{ CGRect rect = [string boundingRectWithSize:CGSizeMake(320, 8000)//限制最大的宽度和高度 options:NSStri转载 2016-12-16 10:55:10 · 526 阅读 · 0 评论 -
iOS获取系统当前时间
NSDate *date = [NSDatedate]; NSDateFormatter* formatter = [[NSDateFormatteralloc] init] ; [formatter setDateFormat:@"yyyy-MM-dd"]; NSString *nowDataStr = [formatte原创 2015-05-27 09:31:27 · 601 阅读 · 0 评论 -
iOS验证码
从服务器端下载验证码图片存储到本地,再用UIImageView显示,刷新的时候从服务器获取新的验证码图片替换本地的图片,显示的时候移除原来的UIImageView加载一个新的,这样就完成可以刷新的验证码,下面附上代码。LoginViewController.m- (void)viewDidLoad { [superviewDidLoad];原创 2015-02-10 12:41:45 · 610 阅读 · 0 评论 -
iOS 自带方法解析json
#pragma mark - json解析-(void) json:(NSString *)jsonUrl{ // 错误信息 NSError *error; // 加载一个NSURL对象 NSURLRequest *request = [NSURLRequestrequestWithURL:[NSURLURLWithStrin原创 2015-08-24 10:02:52 · 680 阅读 · 0 评论 -
iOS 在didSelectAnnotationView方法中获取标题和副标题
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{ // 获得所有MKAnnotationView NSArray *arr = mapView.annotations; // 被点击的MKAnnotationView的标题和副标题转载 2016-02-28 13:10:26 · 2840 阅读 · 0 评论 -
iOS 从一个完整路径中获取不带后缀的文件名
-(NSString*) getFileNameByPath:(NSString*)path{ // 获取带后缀的文件名 path = [path lastPathComponent]; // 去掉文件后缀 path =[path stringByDeletingPathExtension]; return path;}转载 2016-02-23 15:39:34 · 2405 阅读 · 0 评论 -
iOS MD5加密
// #import -(NSString *)md5:(NSString *)str{ const char *cStr = [str UTF8String]; unsigned char result[16]; CC_MD5(cStr, strlen(cStr), result); NSMutableString *hash = [NSMutableStri转载 2016-01-13 14:13:31 · 443 阅读 · 0 评论 -
iOS数组排序
原文链接:http://blog.youkuaiyun.com/bihailantian1988/article/details/8433812// 1 普通数组排序 NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"0",@"8",@"6",@"1",nil]; NSArray *sortedArray = [ar转载 2016-01-09 10:18:53 · 559 阅读 · 0 评论 -
iOS NSDate相关
-(NSArray*) getDayTimeByNum:(NSInteger)num timeInterval:(NSInteger)interval{ NSMutableArray *hoursArr = [NSMutableArray array]; NSDate *date; NSString *currentDateStr; for (int i原创 2016-01-21 14:38:34 · 515 阅读 · 0 评论 -
iOS从相机或相册获取图片并裁剪,再获取裁剪后的图片
-(void) selectWayToGetPicture{ UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"图库", ni原创 2015-11-30 16:42:43 · 6103 阅读 · 0 评论 -
iOS角标
// 角标-(void) initTagWithTitleAndPoint:(NSString*)title originX:(CGFloat)x originY:(CGFloat)y fatherView:(UIView*)view{ UILabel *tagLabel = [[UILabel alloc] init]; tagLabel.frame = CGRectMake原创 2016-01-16 11:11:34 · 767 阅读 · 0 评论 -
iOS定时器
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:NO];-(void)timer:(NSTimer *)timer{NSLog(@"定时器已经执行!");}原创 2015-05-29 15:18:45 · 542 阅读 · 0 评论 -
iOS用UIWebView显示GIF图片
NSData *gifData = [NSDatadataWithContentsOfFile:_path]; _gifWebView = [[UIWebViewalloc] initWithFrame:[UIScreenmainScreen].bounds]; [_gifWebViewsetBackgroundColor:[UIColorclear原创 2015-05-29 15:56:47 · 771 阅读 · 0 评论 -
iOS开发参考
仿余额宝数字渐慢跳动效果:原创 2016-04-09 14:53:53 · 1257 阅读 · 0 评论 -
iOS调用系统日历
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"calshow:"]];如果要选择特定的某一天的话(默认是当前日期),calshow:后面加时间戳格式,也就是NSTimeInterval注意这里计算时间戳调用的方法是-NSTimeInterval nowTimestamp = [[NSDate date]转载 2016-05-19 15:21:16 · 4123 阅读 · 0 评论 -
iOS iOS7以上设置leftBarButtonItem后滑动返回实效
在pushViewController之后加入如下代码:[self.navigationController pushViewController:viewController animated:YES];// 开启iOS7的滑动返回效果if ([self.navigationController respondsToSelector:@selector(interacti转载 2016-05-30 13:48:09 · 521 阅读 · 0 评论 -
iOS NSIndexPath
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];转载 2016-05-03 16:14:09 · 795 阅读 · 0 评论 -
iOS navBar或tabBar的预留间距
self.automaticallyAdjustsScrollViewInsets = YES;转载 2016-04-19 13:55:07 · 972 阅读 · 0 评论 -
iOS修改UITextField的提示语(placeholder)的字体大小和颜色
textField.placeholder =@"呵呵哒";[accountNum setValue:[UIColorgrayColor] forKeyPath:@"_placeholderLabel.textColor"];[accountNumsetValue:[UIFontboldSystemFontOfSize:14]forKeyPath:@"_placeh转载 2015-06-04 09:10:12 · 2591 阅读 · 0 评论 -
iOS生成随机数
//随机生成1-4的随机数int x = (arc4random() %4)+1; NSLog(@"%d",x);原创 2015-06-03 15:17:32 · 483 阅读 · 0 评论 -
iOS UILabel自动换行,自适应高度
UILabel * contentLabel = [[UILabelalloc] init]; NSString * contentStr =@" 曾经七次登上《时代杂志》封面人物的乔布斯,其实是个备受争议的人物。在这位曾被《财富》杂志评为年度最强商人的CEO的经营下,苹果的每一代新产品的简约设计吸引了亿万名粉丝,虽然是名科学家却对其公司所推出的产品有着一定程度的美转载 2015-06-06 15:53:09 · 815 阅读 · 0 评论 -
关于iOS TableView旋转后头部空白的问题
TableView继承自ScrollerView,ScrollerView在iOS7以后会自动留白,加入self.automaticallyAdjusraScrollViewInsets=flase去掉留白。原创 2016-03-24 13:03:25 · 831 阅读 · 0 评论 -
iOS设置状态栏颜色
//修改状态栏的颜色-(UIStatusBarStyle)preferredStatusBarStyle { returnUIStatusBarStyleLightContent;}原创 2015-05-30 18:14:39 · 582 阅读 · 0 评论 -
iOS简单的文件操作
-(NSArray*) getFilesByPath:(NSString*)path{ // 根据路径获取该路径下所有文件 NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *files = [fileManager subpathsOfDirectoryAtPath: path error:nil];原创 2015-11-24 10:04:39 · 688 阅读 · 0 评论 -
iOS调用系统相册、相机界面语言设置为中文
在info.plist里面添加Localized resources can be mixed设置为YES(表示是否允许应用程序获取框架库内语言)转载 2015-11-18 11:21:30 · 3312 阅读 · 0 评论 -
iOS图片缓存开源库SDWebImage的使用
转载自:http://www.cocoachina.com/ios/20141212/10622.html转载 2015-07-30 10:29:37 · 715 阅读 · 0 评论 -
iOS实现弹幕功能
KSBarrageView:https://github.com/Jonear/KSBarrageViewCrazyPeter:https://github.com/CrazyPeter/DanmukuMaster-iOSBarrageRenderer:https://github.com/unash/BarrageRendererHJDanmakuDemo原创 2015-07-29 13:45:21 · 3148 阅读 · 0 评论 -
iPad开发强制横屏
-(NSUInteger)supportedInterfaceOrientations{//强制横屏 returnUIInterfaceOrientationMaskLandscape;}原创 2015-07-27 16:48:19 · 1263 阅读 · 0 评论 -
iOS引导页
GuideViewController.h#import @interface GuideViewController :UIViewControllerUIScrollViewDelegate>@property (nonatomic)UIScrollView *scrollView;@property (nonatomic)NSA转载 2015-07-13 11:03:38 · 602 阅读 · 0 评论 -
iOS圆形按钮
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];button.frame =CGRectMake(40,100, 40, 40);[buttonsetBackgroundImage:image forState:UIControlStateNormal];button.layer.mask原创 2015-07-03 15:20:39 · 695 阅读 · 0 评论 -
iOS UINavigationBar + UITabBar
//TabBar UITabBarController *tabBarCtrl = [[UITabBarControlleralloc]init]; tabBarCtrl.tabBar.backgroundColor = [UIColorwhiteColor]; tabBarCtrl.tabBar.tintColor = [UIColorwhiteCo原创 2015-07-25 11:19:30 · 461 阅读 · 0 评论 -
iOS复制内容到剪切版
UIPasteboard *pasteboard = [UIPasteboardgeneralPasteboard];pasteboard.string =@"呵呵哒";转载 2015-06-12 14:37:06 · 562 阅读 · 0 评论 -
iOS判断应用是否首次启动
if (![[NSUserDefaultsstandardUserDefaults] boolForKey:@"everLaunched"]) { [[NSUserDefaultsstandardUserDefaults] setBool:YESforKey:@"everLaunched"]; [[NSUserDefaultsstanda转载 2015-07-09 16:02:17 · 715 阅读 · 0 评论 -
iOS UILabel添加背景图
[LabelsetBackgroundColor:[UIColorcolorWithPatternImage:[UIImageimageNamed:@"XXX.png"]]];转载 2015-06-06 18:47:38 · 1426 阅读 · 0 评论 -
iOS显示隐藏状态栏
UIApplication *application = [UIApplicationsharedApplication];[applicationsetStatusBarHidden:NO];//设置为YES,则显示原创 2015-06-03 16:01:18 · 659 阅读 · 0 评论 -
iOS自定义cell导致数据加载混乱
转载自:http://www.2cto.com/kf/201308/238449.htmlUITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件。上面主要是一个个的UITableViewCell,可以让UITableViewCell响应一些点击事件,也可以在UITableViewCell中加入UITextField或者UITextView等子视转载 2015-07-30 10:40:38 · 867 阅读 · 0 评论 -
iOS plist文件操作
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *path=[paths objectAtIndex:0]; NSLog(@"path = %@",path); NSString *filena原创 2015-08-26 13:48:29 · 1659 阅读 · 0 评论 -
iOS修改UIPageControl圆点的颜色
pageControl.currentPageIndicatorTintColor = [UIColorwhiteColor];pageControl.pageIndicatorTintColor = [UIColorgrayColor];转载 2015-10-13 15:03:58 · 3494 阅读 · 0 评论 -
iOS解决键盘遮挡输入框的问题
-(void)textFieldDidBeginEditing:(UITextField *)textField{ CGRect frame = textField.frame; int offset = frame.origin.y + 100 - (UISCREEN_HEIGHT - 480.0);//键盘高度 NSTimeInterval animationDuration =原创 2015-10-12 15:55:13 · 1027 阅读 · 0 评论 -
iOS将UIView转换成UIImageView
-(UIImage*)UIViewToUIImageView:(UIView*)view{ CGSize size = view.bounds.size; // 下面的方法:第一个参数表示区域大小;第二个参数表示是否是非透明的如果需要显示半透明效果,需要传NO,否则传YES;第三个参数是屏幕密度 UIGraphicsBeginImageContextWithOptions(size,转载 2015-10-16 17:27:57 · 2654 阅读 · 0 评论