首页 文章 精选 留言 我的

精选列表

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

media jquery 适配ios不同手机

<metacontent="target-densitydpi=320,width=640,user-scalable=no"name="viewport"> 会自动根据dpi320和宽度640的比例,整体页面缩放改变效果 @media (device-height:480px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone4/4s */ .class{} } @media (device-height:568px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone5 */ .class{} } @media (device-height:667px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone6 */ .class{} } @media (device-height:736px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone6 Plus */ .class{} } div{max-width:640px;min-width:320px;margin:0 auto;width:100%;height:100%;} 本文转自Ansue 51CTO博客,原文链接:http://blog.51cto.com/ansue/1639855,如需转载请自行联系原作者

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

iOS表示图下拉刷新控件

UIRefreshControl用的是这个控件。UITableViewController中有refreshControl这个属性。 表格的初始化和数据设置与常规一致。 1:初始化UIRefreshControl控件,并绑定下拉事件 //添加下拉刷新控件 UIRefreshControl*rc=[[UIRefreshControlalloc]init]; rc.attributedTitle= [[NSAttributedStringalloc]initWithString:@"下拉刷新"]; //绑定下拉事件 [rcaddTarget:selfaction:@selector(refreshTableView)forControlEvents:UIControlEventValueChanged]; self.refreshControl= rc; 2 :添加下拉事件函数,在下拉事件中请求数据和修改控件状态,绑定回调函数 //下拉动作响应函数。 -(void)refreshTableView { if(self.refreshControl.refreshing){ self.refreshControl.attributedTitle= [[NSAttributedStringalloc]initWithString:@"加载中。。。"]; //添加模拟数据 NSDate*now = [[NSDatealloc]init]; //添加回调函数,模拟请求。需要在请求结束后关闭加载中状态。 [selfperformSelector:@selector(callBackMethod:)withObject:nowafterDelay:3]; } } 3:在回调函数中修改控件状态并更新数据和表格视图。 -(void)callBackMethod:(id)obj { //结束加载的状态 [self.refreshControlendRefreshing]; self.refreshControl.attributedTitle= [[NSAttributedStringalloc]initWithString:@"下拉刷新"]; //添加数据,刷新表格 [self.listDataaddObject:(NSDate*)obj]; [self.tableViewreloadData]; } 本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1772577,如需转载请自行联系原作者

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

ios截屏使用的方法

- (UIImage*)getimage{//截屏使用的方法 CGSize imageSize = [[UIScreen mainScreen] bounds].size; if (NULL != UIGraphicsBeginImageContextWithOptions) { UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); } else { UIGraphicsBeginImageContext(imageSize); } CGContextRef context = UIGraphicsGetCurrentContext(); for (UIWindow *window in [[UIApplication siharedApplication] windows]) { if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) { CGContextSaveGState(context); CGContextTranslateCTM(context, [window center].x, [window center].y); CGContextConcatCTM(context, [window transform]); CGContextTranslateCTM(context, -[window bounds].size.width * [[window layer] anchorPoint].x, -[window bounds].size.height * [[window layer] anchorPoint].y); [[window layer] renderInContext:context]; CGContextRestoreGState(context); } } UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } 本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1616382,如需转载请自行联系原作者

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

iOS AFNetWorking下同步异步请求

//阻塞 - (User *)findUser:(NSNumber *)userID { NSString *url = [NSString stringWithFormat:@"%@/s/account/find-user/",ServerBaseURL]; NSMutableDictionary *requestParms = [[NSMutableDictionary alloc] init]; [requestParms setObject:userID forKey:@"userId"]; AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer]; NSMutableURLRequest *request = [requestSerializer requestWithMethod:@"POST" URLString:url parameters:requestParms error:nil]; AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPResponseSerializer*responseSerializer = [AFJSONResponseSerializerserializer]; [requestOperation setResponseSerializer:responseSerializer]; [requestOperation start]; [requestOperation waitUntilFinished]; NSDictionary *userInfo = [[requestOperation responseObject] objectForKey:@"user"]; if (userInfo != nil) { 这里对结果处理 return xxxx } return nil; } //异步 NSString *url = [NSString stringWithFormat:@"%@/s/account/signin/", ServerBaseURL]; NSMutableDictionary *requestParms = [[NSMutableDictionary alloc] init]; //设置参数 [requestParms setObject:loginName forKey:@"loginname"]; [httpManager POST:url parameters:requestParms success:^(AFHTTPRequestOperation *operation, id responseObject) { //成功 } failure:^(AFHTTPRequestOperation *operation, NSError *error) { //失败 }]; 本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1772532,如需转载请自行联系原作者

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

ios15--综合小例子

// // XMGViewController.m,控制器类 #import "XMGViewController.h" #import "XMGShop.h" @interface XMGViewController () // 购物车 @property (weak, nonatomic) IBOutlet UIView *shopCarView; // 添加按钮 @property (weak, nonatomic) IBOutlet UIButton *addButton; // 删除按钮 @property (weak, nonatomic) IBOutlet UIButton *removeButton; /** 数据数组 */ @property (nonatomic, strong) NSArray *dataArr; @end @implementation XMGViewController /** * 懒加载 */ - (NSArray *)dataArr{ if (_dataArr == nil) { // 加载数据 // 1.获取全路径 NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"shopData.plist" ofType:nil];//Supporting Files下面的shopData.plist文件。 self.dataArr = [NSArray arrayWithContentsOfFile:dataPath]; //dataPath = @"/Users/mctc/Library/Developer/CoreSimulator/Devices/4E7E6AB7-BB75-4C2C-9D87-21A0369A3DD6/data/Containers/Bundle/Application/A855282B-7D1A-450A-B3C3-8ACE93443577/03-综合练习.app/shopData.plist" 0x00007fafe150ef70 NSLog(@"%@",self.dataArr); //调用了get方法。 /*( { icon = danjianbao; name = "\U5355\U5305"; }, { icon = qianbao; name = "\U94b1\U5305"; })*/ // 字典转模型对象 // 创建临时数组 NSMutableArray *tempArray = [NSMutableArray array]; for (NSDictionary *dict in _dataArr) { // 创建shop对象 /* // XMGShop *shop = [[XMGShop alloc] initWithIcon:dict[@"icon"] name:dict[@"name"]]; // XMGShop *shop = [XMGShop shopWithIcon:dict[@"icon"] name:dict[@"name"]]; // shop.name = dict[@"name"]; // shop.icon = dict[@"icon"]; */ XMGShop *shop = [XMGShop shopWithDict:dict]; // 把模型装入数组 [tempArray addObject:shop]; } self.dataArr = tempArray; } return _dataArr; } // 初始化数据 - (void)viewDidLoad { [super viewDidLoad]; /*类前缀 // Foundation NSString; NSArray; NSDictionary; NSURL; // UIKit UIView; UIImageView; UISwitch; */ } /** * 添加到购物车 * * @param button 按钮 */ - (IBAction)add:(UIButton *)button { /***********************1.定义一些常量*****************************/ // 1.总列数 NSInteger allCols = 3; // 2.商品的宽度 和 高度 CGFloat width = 80; CGFloat height = 100; // 3.求出水平间距 和 垂直间距 CGFloat hMargin = (self.shopCarView.frame.size.width - allCols * width) / (allCols -1); CGFloat vMargin = (self.shopCarView.frame.size.height - 2 * height) / 1; // 4. 设置索引 NSInteger index = self.shopCarView.subviews.count; // 5.求出x值 CGFloat x = (hMargin + width) * (index % allCols); CGFloat y = (vMargin + height) * (index / allCols); /***********************2.创建一个商品*****************************/ // 1.创建商品的view UIView *shopView = [[UIView alloc] init]; // 2.设置frame shopView.frame = CGRectMake(x, y, width, height); // 3.设置背景颜色 shopView.backgroundColor = [UIColor greenColor]; // 4.添加到购物车 [self.shopCarView addSubview:shopView]; // 5.创建商品的UIImageView对象 UIImageView *iconView = [[UIImageView alloc] init]; iconView.frame = CGRectMake(0, 0, width, width); iconView.backgroundColor = [UIColor blueColor]; [shopView addSubview:iconView]; // 6.创建商品标题对象 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.frame = CGRectMake(0, width, width, height - width); titleLabel.backgroundColor = [UIColor yellowColor]; titleLabel.textAlignment = NSTextAlignmentCenter; // 居中 [shopView addSubview:titleLabel]; /***********************3.设置数据*****************************/ // 设置数据 XMGShop *shop = self.dataArr[index]; iconView.image = [UIImage imageNamed:shop.icon]; titleLabel.text = shop.name; /***********************4.设置按钮的状态*****************************/ button.enabled = (index != 5); // 5.设置删除按钮的状态 self.removeButton.enabled = YES; } /** * 从购物车中删除 * * @param button 按钮 */ - (IBAction)remove:(UIButton *)button { // 1. 删除最后一个商品 UIView *lastShopView = [self.shopCarView.subviews lastObject]; [lastShopView removeFromSuperview]; // 3. 设置添加按钮的状态 self.addButton.enabled = YES; // 4. 设置删除按钮的状态 /* if (self.shopCarView.subviews.count == 0) { self.removeButton.enabled = NO; } */ self.removeButton.enabled = (self.shopCarView.subviews.count != 0); } @end // // XMGShop.h #import <Foundation/Foundation.h> @interface XMGShop : NSObject /** 图片的名称 */ @property (nonatomic, copy) NSString *icon; /** 商品的名称 */ @property (nonatomic, copy) NSString *name; // 提供构造方法 /* - (instancetype)initWithIcon: (NSString *)icon name: (NSString *)name; + (instancetype)shopWithIcon: (NSString *)icon name: (NSString *)name; */ - (instancetype)initWithDict:(NSDictionary *)dict; + (instancetype)shopWithDict:(NSDictionary *)dict; @end // // XMGShop.m #import "XMGShop.h" @implementation XMGShop /* - (instancetype)initWithIcon:(NSString *)icon name:(NSString *)name{ if (self = [super init]) { self.icon = icon; self.name = name; } return self; } + (instancetype)shopWithIcon:(NSString *)icon name:(NSString *)name{ return [[self alloc] initWithIcon:icon name:name]; } */ /*构造方法,一般一共对象方法和类方法*/ - (instancetype)initWithDict:(NSDictionary *)dict{ if (self = [super init]) { self.icon = dict[@"icon"]; self.name = dict[@"name"]; } return self; } + (instancetype)shopWithDict:(NSDictionary *)dict{ return [[self alloc] initWithDict:dict];//self alloc创建了一个类对象。 } @end 本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/7466604.html,如需转载请自行联系原作者

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

iOS 分组索引和索引分区

1.新建工程名SearchViewController,File->New->Projectr->SingleView Application->next 2.添加协议和声明变量 还需要让类遵循UISearchBarDelegate协议,除了充当表视图的委托之外还需要让它充当搜索栏的委托。 @interfaceViewController :UIViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate> { UITableView*tableavaieGroup; UISearchBar*search; NSMutableDictionary*names; NSMutableArray*keys; BOOLisSearching; } 3.添加plist文件,再到ViewDidLoad中初始化视图 - (void)viewDidLoad { //读取plist文件 NSString*path=[[NSBundlemainBundle]pathForResource:@"Property List"ofType:@"plist"]; NSDictionary*dictionary=[[NSDictionaryalloc]initWithContentsOfFile:path]; //self.names=dictionary; self.allNames=dictionary; //读取字典中的键存储在数组中 //NSArray *array=[[namesallKeys]sortedArrayUsingSelector:@selector(compare:)]; //self.myKey=array; [selfresetSearch]; [tableViewGroupreloadData]; [tableViewGroupsetContentOffset:CGPointMake(0.0, 44.0)animated:NO]; [superviewDidLoad];} 4.实现委托方法 从数组中读取字典中的plist文件有几个分区 方法获取一个可重用单元,如果单元不存在则创建一个新的单元。然后从对应查询的数组中获取对象,将单元的文本设置成控制器标题并返回单元 - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { staticNSString*DisclosureCellIdentifier =@"DisclosureCellIdentifier"; UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:DisclosureCellIdentifier]; if(cell ==nil) {//创建一个新的单元 cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:DisclosureCellIdentifier]; } //对应查询数组中获取的对象,将单元文本设置成控制器标题并返回单元 NSUIntegerrow=[indexPathrow]; NSString*rowData=[listDataobjectAtIndex:row]; cell.textLabel.text=rowData; cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; returncell; } 5.添加搜索栏委托方法 搜索栏有许多在其委托上调用的方法,当用户单击键盘上的返回按钮或搜索键时,将调用searchBarBookmarkButtonClicked,此方法从搜索栏获取搜索短语,并调用我们的搜索方法,这个搜索方法将删除names中不匹配的名称和keys中的空分区: -(void)searchBarBookmarkButtonClicked:(UISearchBar*)searchBar { NSString*searchTerm=[searchBartext]; [selfhandleSearchForTerm:searchTerm]; } 运行结果如下: (点击搜索框进行搜索“egg”,出现第二个页面) 6)NSDictinary遵循NSMutableCopying协议,该协议返回一个NSmutableDictionary,但是这个方法创建的是浅副本。也就是说调用mutableCopy方法时,它将创建一个新的NSmutableDictionary对象,该对象拥有源字典所拥有的所有对象,他们并不是副本,而是相同的实际对象,由于字典中存有数组,如果我们从副本的数组中删除对象,这些对象也会从原字典的数组中删除,因为副本和源都指向相同的对象,在这种情况下元数组是不可改变 的所以无法删除对象,解决这个问题,需要为存有数组的字典创建一个深层可变副本, Next-> 之后 Categroy on (NSDictionary) Categrpy(MutableDeepCopy) 此方法创建一个新的可变字典,然后在原字典中所有的键进行迭代,为它遇到的每个数组创建可变副本。 -(NSMutableDictionary*)mutableDeepCopy { NSMutableDictionary*returnDict=[[NSMutableDictionaryalloc]initWithCapacity:[selfcount]]; NSArray*keys=[selfallKeys]; //NSArray *keys=[self ]; // 因为在原有的mutableCopy中,只会对第一层对象进行mutable化. // 比如NSDictionary嵌套NSArray的话. // 原有的MutableCopy只会返回NSMutableDictionary,而不会使其子元素也变为NSMutableArray. // 而这种方法实际上类似递归的结构. //循环读取复制每一个元素 for(idkeyinkeys) { idoneValue=[selfvalueForKey:key]; idoneCopy=nil; //如果key对应的元素可以响应mutableDeepCopy方法(还是NSDictionary),调用mutableDeepCopy方法复制 if([oneValuerespondsToSelector:@selector(mutableDeepCopy)]) oneCopy=[oneValuemutableDeepCopy]; elseif([oneValuerespondsToSelector:@selector(mutableCopy)]) oneCopy=[oneValuemutableCopy]; if(oneCopy==nil) oneCopy=[oneValuecopy]; [returnDictsetValue:oneCopyforKey:key]; } returnreturnDict; } 7)要想在运行时搜索框后有一个Cancel按钮只需在Option中勾选Shows Cancel Button即可,如下图: 当用户单击Cancel按钮时,程序会将搜索短语设置为空,然后重置搜索,并重新加载数据一显示所有名称,此外,还要让搜索栏放弃第一响应者状态,这样键盘就不再起作用,以便于用户重新处理表视图。 本文转自HDDevTeam 51CTO博客,原文链接:http://blog.51cto.com/hddev/1218230,如需转载请自行联系原作者

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

mysql支持IOS的Emoji表情

原因: UTF-8编码有可能是两个、三个、四个字节。Emoji表情是4个字节,而Mysql的utf8编码最多3个字节,所以数据插不进去。 解决办法: 将Mysql的编码从utf8转换成utf8mb4 步骤: 1.修改mysql配置文件 my.ini default-character-set=utf8mb4 character-set-server=utf8mb4 2.加入 [client] port=3306 default-character-set=utf8mb4 [mysqld]下加入 character-set-client-handshake= FALSE collation-server= utf8mb4_general_ci init_connect='SET NAMES utf8mb4' 3.重启mysql 4.修改输入键盘表情的字段的编码为utf8mb4_general_ci 本文转自 海角在眼前 博客园博客,原文链接: http://www.cnblogs.com/lovesong/p/3986754.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

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

腾讯云软件源

腾讯云软件源

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

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

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

用户登录
用户注册
修改密码
忘记密码