首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

iOS:网络检测

若想App通过审核,则必须对网络环境进行判断,在无网络的时候进行提醒等处理。 Apple 的 例程 Reachability 中介绍了取得/检测网络状态的方法。要在应用程序程序中使用Reachability,首先要完成如下两部:1.1. 添加源文件:在你的程序中使用Reachability只须将该例程中的 Reachability.h 和 Reachability.m 拷贝到你的工程中。如下图:1.2.添加framework:将SystemConfiguration.framework添加进工程。如下图:2. 网络状态Reachability.h中定义了三种网络状态:typedef enum {NotReachable = 0,//无连接ReachableViaWiFi,//使用3G/GPRS网络ReachableViaWWAN//使用WiFi网络} NetworkStatus;因此可以这样检查网络状态:Reachability *r = [Reachability reachabilityWithHostName:@“www.apple.com”];switch ([r currentReachabilityStatus]) {case NotReachable:// 没有网络连接break;case ReachableViaWWAN:// 使用3G网络break;case ReachableViaWiFi:// 使用WiFi网络break;} check:http://blog.sina.com.cn/s/blog_6f40a0e70100srip.html 本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2013/01/16/2862914.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

ios隐藏键盘

1.点击页面空白处隐藏键盘 给viewController里面复写-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法,在这个方法里面,给先前获取了输入焦点的UITextField发送resignFirstResponder消息 例如: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.baseCountTextField resignFirstResponder]; } 2.点击键盘上的return键隐藏键盘 给UITextField绑定Did End on Exit事件处理函数,并在其中给UITextField发送resignFirstResponder 消息。 3.给整个页面设置一个大的UIControl类的控件 这种做法是将一个UIControl控件作为底子,然后在上面放其他控件,最后给作为底子的UIControl控件绑定touch up inside事件处理逻辑。 4.修改viewController的view的类型为UIControl 实际上跟第三种做法类似 本文转自leipei博客园博客,原文链接:http://www.cnblogs.com/leipei2352/p/3589506.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

【IOS】Target membership

Target membership是指XCode中,一个文件属于哪一个工程,在XCode左侧的工程面板中选中一个文件,在XCode右侧的属性面板中会显示其Target Membership,如下图。 当前的文件AppDelegate.m属于书谱这个Target。 Target Membership的一些属性。 .h 文件没有Target Membership 文件夹引用有Target Membership,其子文件继承该文件夹的Target Membership。但面板中不显示子文件的Target Membership。 以前遇到一个错误,就是UIImage创建的时候返回nil,仔细查看发现,图片的Target Membership选项没有勾上。这个错误比较难以发现,特此记之。 == 本文转自zdd博客园博客,原文链接:http://www.cnblogs.com/graphics/p/4117353.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS UIView contentMode

Content Modes contentMode是UIView的属性,这个属性的值决定了,当视图的几何形状变化时如何复用它的内容。当视图第一次展示前,它会将自己的内容渲染成一张底层的bitmap. 然后视图的几何变化都不会使bitmap重新生成。而视图contentMode属性的值决定了bitmap是否缩放、位置在哪儿(固定在左边、右边、上面、下面、居中)。默认情况下,contentMode的值是UIViewContentModeScaleToFill。 contentMode啥时候起作用呢? 视图frame或bounds的高宽发生变化 赋给 view的transform属性的值带有scale UIViewContentModeScaleToFill Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary. 改变内容的高宽比例,缩放内容,UIView中完整显示内容,填满UIView, UIViewContentModeScaleAspectFit Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent. 保持内容的高宽比,缩放内容,完整显示内容,最大化填充UIview,没填充上的区域透明 UIViewContentModeScaleAspectFill Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds. 保持内容高宽比,缩放内容,超出视图的部分内容会被裁减,填充UIView 需要把View的 clipsToBounds 设置为YES; UIViewContentModeRedraw The option to redisplay the view when the bounds change by invoking the setNeedsDisplay method. 当View的bounds改变,系统会调用setNeedsDisplay,重新绘制视图 UIViewContentModeCenter The option to center the content in the view’s bounds, keeping the proportions the same. 不缩放,内容在视图中间 UIViewContentModeTop The option to center the content aligned at the top in the view’s bounds. UIViewContentModeBottom The option to center the content aligned at the bottom in the view’s bounds. UIViewContentModeLeft The option to align the content on the left of the view. UIViewContentModeRight The option to align the content on the right of the view. UIViewContentModeTopLeft The option to align the content in the top-left corner of the view. UIViewContentModeTopRight The option to align the content in the top-right corner of the view. UIViewContentModeBottomLeft The option to align the content in the bottom-left corner of the view. UIViewContentModeBottomRight The option to align the content in the bottom-right corner of the view. 效果图: image 参考链接stackoverflow Content Modes

优秀的个人博客,低调大师

iOS ReSideMenu 使用

pod 'RESideMenu', '~> 4.0.7' github 地址 ;https://github.com/romaonthego/RESideMenu 不缩放self.scaleContentView = NO; 1. storyborad 添加 slideView 创建 一个 SlideViewController 继承 resideview main.storyBoard 中 class 是 SlideViewController 添加 storyboradId 用于区分 2. storyboard 添加 LeftMenuViewController 添加 storyboradId 用于区分 3.storyboard 添加 contentViewController添加 storyboradId 用于区分 拖入一个 navigation Controller 删除 tableViewController 拖入一个 UIViewController 连线到 navigation Controller 的rootView 删除里面的 view 等 拖入一个 navigation Controller Item 添加 一个 bar button item 连线自己 presentLeftViewController 运行 。。。 // // SlideViewController.m // BlogIteye // // Created by youbao on 16/10/22. // Copyright © 2016年 youbao. All rights reserved. // #import "SlideViewController.h" #import "RESideMenu.h" @interface SlideViewController ()<RESideMenuDelegate> @end @implementation SlideViewController - (void)awakeFromNib { self.menuPreferredStatusBarStyle = UIStatusBarStyleLightContent; self.contentViewShadowColor = [UIColor blackColor]; self.contentViewShadowOffset = CGSizeMake(0, 0); self.contentViewShadowOpacity = 0.6; self.contentViewShadowRadius = 12; self.contentViewShadowEnabled = YES; self.scaleContentView = NO; // 不缩放 self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"]; self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"]; // self.rightMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"rightMenuViewController"]; //self.backgroundImage = [UIImage imageNamed:@"Stars"]; self.delegate = self; } #pragma mark - #pragma mark RESideMenu Delegate - (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController { NSLog(@"willShowMenuViewController: %@", NSStringFromClass([menuViewController class])); } - (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController { NSLog(@"didShowMenuViewController: %@", NSStringFromClass([menuViewController class])); } - (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController { NSLog(@"willHideMenuViewController: %@", NSStringFromClass([menuViewController class])); } - (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController { NSLog(@"didHideMenuViewController: %@", NSStringFromClass([menuViewController class])); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end 捐助开发者 在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。 谢谢您的赞助,我会做的更好!

优秀的个人博客,低调大师

iOS coredata 使用

// // AppDelegate.h // IteyeBlog // // Created by youbao on 16/9/24. // Copyright © 2016年 youbao. All rights reserved. // #import <UIKit/UIKit.h> #import <CoreData/CoreData.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext; - (NSURL *)applicationDocumentsDirectory; @end // // AppDelegate.m // IteyeBlog // // Created by youbao on 16/9/24. // Copyright © 2016年 youbao. All rights reserved. // #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //TODO: return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Saves changes in the application's managed object context before the application terminates. [self saveContext]; } #pragma mark - Core Data stack @synthesize managedObjectContext = _managedObjectContext; @synthesize managedObjectModel = _managedObjectModel; @synthesize persistentStoreCoordinator = _persistentStoreCoordinator; - (NSURL *)applicationDocumentsDirectory { // The directory the application uses to store the Core Data store file. This code uses a directory named "com.curiousby.baoyou.cn.IteyeBlog" in the application's documents directory. return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; } - (NSManagedObjectModel *)managedObjectModel { // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. if (_managedObjectModel != nil) { return _managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"IteyeBlog" withExtension:@"momd"]; _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return _managedObjectModel; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. if (_persistentStoreCoordinator != nil) { return _persistentStoreCoordinator; } // Create the coordinator and store _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"IteyeBlog.sqlite"]; NSError *error = nil; NSString *failureReason = @"There was an error creating or loading the application's saved data."; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { // Report any error we got. NSMutableDictionary *dict = [NSMutableDictionary dictionary]; dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data"; dict[NSLocalizedFailureReasonErrorKey] = failureReason; dict[NSUnderlyingErrorKey] = error; error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; // Replace this with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return _persistentStoreCoordinator; } - (NSManagedObjectContext *)managedObjectContext { // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) if (_managedObjectContext != nil) { return _managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (!coordinator) { return nil; } _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [_managedObjectContext setPersistentStoreCoordinator:coordinator]; return _managedObjectContext; } #pragma mark - Core Data Saving support - (void)saveContext { NSManagedObjectContext *managedObjectContext = self.managedObjectContext; if (managedObjectContext != nil) { NSError *error = nil; if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } } @end // // ViewController.m // IteyeBlog // // Created by youbao on 16/9/24. // Copyright © 2016年 youbao. All rights reserved. // #import "ViewController.h" #import "AFHTTPSessionManager.h" #import "UIImageView+WebCache.h" #import "AppDelegate.h" #import "OfferDBEntity.h" static NSString *const IconUrl = @"http://ods5pg0qp.bkt.clouddn.com/iteyeblog/icon.png"; @interface ViewController () @property (weak, nonatomic) IBOutlet UIButton *btn; @property (weak, nonatomic) IBOutlet UIImageView *image; @property (weak, nonatomic) IBOutlet UIButton *addLable; @property (weak, nonatomic) IBOutlet UIButton *selectLable; @property (weak, nonatomic) IBOutlet UIButton *updateLable; @property (weak, nonatomic) IBOutlet UIButton *delLable; @property(nonatomic,retain) AppDelegate* appDelegate; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate]; } -(IBAction) add:(id)sender{ OfferDBEntity *entity = (OfferDBEntity *) [NSEntityDescription insertNewObjectForEntityForName:@"OfferDBEntity" inManagedObjectContext:self.appDelegate.managedObjectContext]; entity.iconurl = IconUrl; entity.name = @"baoyou it"; entity.desc = @"IT 工程师"; NSError* error; BOOL isSaveSuccess=[self.appDelegate.managedObjectContext save:&error]; if (!isSaveSuccess) { NSLog(@"Error:%@",error); }else{ NSLog(@"Save successful!"); } } -(IBAction) select:(id)sender{ NSFetchRequest* request=[[NSFetchRequest alloc] init]; NSEntityDescription* entity=[NSEntityDescription entityForName:@"OfferDBEntity" inManagedObjectContext:self.appDelegate.managedObjectContext]; [request setEntity:entity]; NSError* error=nil; NSMutableArray* mutableFetchResult=[[self.appDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; if (mutableFetchResult==nil) { NSLog(@"error:%@",error); } NSLog(@"the count of entity: %ld",[mutableFetchResult count]); for (OfferDBEntity *entity in mutableFetchResult) { NSLog(@"iconrl=%@,name=%@,desc=%@",entity.iconurl,entity.name ,entity.desc); } } -(IBAction) update:(id)sender{ NSFetchRequest* request=[[NSFetchRequest alloc] init]; NSEntityDescription* user=[NSEntityDescription entityForName:@"OfferDBEntity" inManagedObjectContext:self.appDelegate.managedObjectContext]; [request setEntity:user]; //查询条件 NSPredicate* predicate=[NSPredicate predicateWithFormat:@"name==%@",@"baoyou it"]; [request setPredicate:predicate]; NSError* error=nil; NSMutableArray* mutableFetchResult=[[self.appDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; if (mutableFetchResult==nil) { NSLog(@"error:%@",error); } NSLog(@"the count of entity: %ld",[mutableFetchResult count]); //更新age后要进行保存,否则没更新 for (OfferDBEntity *entity in mutableFetchResult) { [entity setDesc: @"baoyou desc"]; } [self.appDelegate.managedObjectContext save:&error]; } -(IBAction) del:(id)sender{ NSFetchRequest* request=[[NSFetchRequest alloc] init]; NSEntityDescription* user=[NSEntityDescription entityForName:@"OfferDBEntity" inManagedObjectContext:self.appDelegate.managedObjectContext]; [request setEntity:user]; NSPredicate* predicate=[NSPredicate predicateWithFormat:@"name==%@",@"baoyou it"]; [request setPredicate:predicate]; NSError* error=nil; NSMutableArray* mutableFetchResult=[[self.appDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; if (mutableFetchResult==nil) { NSLog(@"Error:%@",error); } NSLog(@"The count of entry: %ld",[mutableFetchResult count]); for (OfferDBEntity *entity in mutableFetchResult) { [self.appDelegate.managedObjectContext deleteObject:entity]; } if ([self.appDelegate.managedObjectContext save:&error]) { NSLog(@"Error:%@,%@",error,[error userInfo]); } } @end 捐助开发者 在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。 谢谢您的赞助,我会做的更好!

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册