iOS开发中遇到的小问题-----总结

iOS开发中遇到的小问题-----总结,第1张

1、统一收键盘的方法

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

2、提示框

BBAlertView alert = [[BBAlertView alloc] initWithStyle:BBAlertViewStyleDefault

Title:@"删除订单"

message:@"是否删除订单,"

customView:nil

delegate:self

cancelButtonTitle:L(@"取消")

otherButtonTitles:L(@"确认")];

[alert setCancelBlock:^{

}];

[alert setConfirmBlock:^{

[self orderDidRemovePressDown:tempDic Index:indexsection];

}];

[alert show];

3、的自适应功能

selfbrandImagecontentMode = UIViewContentModeScaleAspectFit;

4、cocoaPods清除缓存问题

$ sudo rm -fr ~/cocoapods/repos/master

$ pod setup

5、设置显示键盘的样式

textViewkeyboardType =UIKeyboardTypeDefault;

//设置键盘右下角为完成(中文输入法下)

textViewreturnKeyType=UIReturnKeyDone;

6、输出当前时间

NSDateFormatter dateFormatter=[[NSDateFormatter alloc]init];

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ssSSS"];

NSLog(@"当前毫秒时间1==%@",[dateFormatter stringFromDate:[NSDate date]]);

7、显示两秒然后消失

UILabel lab=[[UILabel alloc]initWithFrame:CGRectMake(60,Main_Screen_Height-64-49-60, Main_Screen_Width-120, 50)];

labbackgroundColor=[UIColor grayColor];

ViewRadius(lab, 20);

labtextAlignment=NSTextAlignmentCenter;

labtext=@"请先进行实名制验证";

[selfview addSubview:lab];

[UILabel animateWithDuration:2 animations:^{

labalpha=0;

}completion:^(BOOL finished) {

[lab removeFromSuperview];

}];

8、设置placeholder属性的大小和颜色

[_phoneFie setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabeltextColor"];

[_phoneFie setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabelfont"];

_phoneFiereturnKeyType=UIReturnKeyDone;

9、设置cell的交互完全不可以使用

//[cellTwo setUserInteractionEnabled:NO];

//设置cell不可以点击,但是上面的子控件可以交互

cellTwoselectionStyle=UITableViewCellSelectionStyleNone;

10、将textField的placeholder 属性的字体向右边移动5

_fieldleftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10Width_375, _fieldframesizeheight)];

_fieldleftViewMode = UITextFieldViewModeAlways;

11、开新线程使按钮上的时间变化

-(void)startTime{

__block int timeout=60; //倒计时时间

UIButton btn=(UIButton )[selfview viewWithTag:1000];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);

dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),10NSEC_PER_SEC, 0); //每秒执行

dispatch_source_set_event_handler(_timer, ^{

if(timeout<=0){

dispatch_source_cancel(_timer);

dispatch_async(dispatch_get_main_queue(), ^{

[btn setTitle:@"发送验证码" forState:UIControlStateNormal];

btnenabled = YES;

});

}else{

//  int minutes = timeout / 60;

int miao = timeout % 60;

if (miao==0) {

miao = 60;

}

NSString strTime = [NSString stringWithFormat:@"%2d", miao];

dispatch_async(dispatch_get_main_queue(), ^{

[btn setTitle:[NSString stringWithFormat:@"剩余%@秒",strTime] forState:UIControlStateNormal];

btnenabled = NO;

});

timeout--;

}

});

dispatch_resume(_timer);

}

12、隐藏TableView 中多余的行

UIView view=[[UIView alloc]initWithFrame:CGRectZero];

[_tabelView setTableFooterView:view];

13、UIView添加背景

UIImage image=[UIImage imageNamed:@"friend750"];

headSeVlayercontents=(id)imageCGImage;

14、UITableView取消选中状态

[tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中

15、带属性的字符串

NSFontAttributeName  字体

NSParagraphStyleAttributeName  段落格式

NSForegroundColorAttributeName  字体颜色

NSBackgroundColorAttributeName  背景颜色

NSStrikethroughStyleAttributeName 删除线格式

NSUnderlineStyleAttributeName      下划线格式

NSStrokeColorAttributeName        删除线颜色

NSStrokeWidthAttributeName 删除线宽度

NSShadowAttributeName  阴影

1  使用实例

UILabel testLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 320, 30)];

testLabelbackgroundColor = [UIColor lightGrayColor];

testLabeltextAlignment = NSTextAlignmentCenter;

NSMutableAttributedString AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"今天天气不错呀"];

[AttributedStr addAttribute:NSFontAttributeName

value:[UIFont systemFontOfSize:160]

range:NSMakeRange(2, 2)];

[AttributedStr addAttribute:NSForegroundColorAttributeName

value:[UIColor redColor]

range:NSMakeRange(2, 2)];

testLabelattributedText = AttributedStr;

[selfview addSubview:testLabel];

16、加大按钮的点击范围

把UIButton的frame 设置的大一些,然后给UIButton设置一个小些的

[tmpBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];

// 注意这里不能用setBackgroundImage

[tmpBtn setImage:[UIImage imageNamed:@"testBtnImage"] forState:UIControlStateNormal];

17、//避免self的强引用

__weak ViewController weakSelf = self;

18、//类别的创建

command +n ——>Objective-C File———>(File Type  选择是类别还是扩展)———>(Class  选择为哪个控件写类别)

19、修改UITableview 滚动条颜色的方法

selftableViewindicatorStyle=UIScrollViewIndicatorStyleWhite;

20、利用UIWebView显示pdf文件

webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

[webView setDelegate:self];

[webView setScalesPageToFit:YES];

[webViewsetAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];

[webView setAllowsInlineMediaPlayback:YES];

[selfview addSubview:webView];

NSString pdfPath = [[NSBundle mainBundle]pathForResource:@"ojc" ofType:@"pdf"];

NSURL url = [NSURLfileURLWithPath:pdfPath];

NSURLRequest request = [NSURLRequestrequestWithURL:url

cachePolicy:NSURLRequestUseProtocolCachePolicy

timeoutInterval:5];

[webView loadRequest:request];

21、将plist文件中的数据赋给数组

NSString thePath = [[NSBundle mainBundle]pathForResource:@"States" ofType:@"plist"];

NSArray array = [NSArrayarrayWithContentsOfFile:thePath];

22、隐藏状态栏

[[UIApplication shareApplication]setStatusBarHidden: YES animated:NO];

23、给navigation  Bar  设置title颜色

UIColor whiteColor = [UIColor whiteColor];

NSDictionary dic = [NSDictionary dictionaryWithObject:whiteColor forKey:NSForegroundColorAttributeName];

[selfnavigationControllernavigationBar setTitleTextAttributes:dic];

24、使用AirDrop 进行分享

NSArray array = @[@"test1", @"test2"];

UIActivityViewController activityVC = [[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];

[self presentViewController:activityVC animated:YES

completion:^{

NSLog(@"Air");

}];

25、把tableview里面Cell的小对勾的颜色改成别的颜色

_mTableViewtintColor = [UIColor redColor];

26、UITableView去掉分割线

_tableViewseparatorStyle = NO;

27、正则判断手机号码地址格式

- (BOOL)isMobileNumber:(NSString )mobileNum {

//    电信号段:133/153/180/181/189/177

//    联通号段:130/131/132/155/156/185/186/145/176

//    移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178

//    虚拟运营商:170

NSString MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";

NSPredicate regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

return [regextestmobile evaluateWithObject:mobileNum];

}

28、控制交易密码位数

-(BOOL)textField:(UITextField )textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString )string{

if (textFieldtextlength >=6){

[MBProgressHUD showMessage:@"密码为6位" afterDelay:18];

return NO;

}

return YES;

}

29、判断是不是空

if ([real_name isKindOfClass:[NSNull class]] ) {

return NO;}

30、点击号码拨打电话

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://400966220"]];

31、控制UITabbar的选择哪一个

[selftabBarController setSelectedIndex:1];

32、获取当前App的版本号

NSDictionary infoDictionary = [[NSBundle mainBundle] infoDictionary];

CFShow(infoDictionary);

// app名称

NSString app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];

// app版本

NSString app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

// app build版本

NSString app_build = [infoDictionary objectForKey:@"CFBundleVersion"];

33、苹果app权限NSPhotoLibraryUsageDescriptionApp需要您的同意,才能访问相册NSCameraUsageDescriptionApp需要您的同意,才能访问相机NSMicrophoneUsageDescriptionApp需要您的同意,才能访问麦克风NSLocationUsageDescriptionApp需要您的同意,才能访问位置NSLocationWhenInUseUsageDescriptionApp需要您的同意,才能在使用期间访问位置NSLocationAlwaysUsageDescriptionApp需要您的同意,才能始终访问位置NSCalendarsUsageDescriptionApp需要您的同意,才能访问日历NSRemindersUsageDescriptionApp需要您的同意,才能访问提醒事项NSMotionUsageDescriptionApp需要您的同意,才能访问运动与健身NSHealthUpdateUsageDescriptionApp需要您的同意,才能访问健康更新NSHealthShareUsageDescriptionApp需要您的同意,才能访问健康分享NSBluetoothPeripheralUsageDescriptionApp需要您的同意,才能访问蓝牙NSAppleMusicUsageDescriptionApp需要您的同意,才能访问媒体资料库

34、控件设置边框

_describTextlayerborderColor = [[UIColor colorWithRed:2150 / 2550 green:2150 / 2550 blue:2150 / 2550 alpha:1] CGColor];

_describTextlayerborderWidth = 10;

_describTextlayercornerRadius = 40;

_describTextclipsToBounds = YES;

35、//隐藏电池条的方法

-(BOOL)prefersStatusBarHidden{

return YES;

}

36、延时 *** 作

[NSThread sleepForTimeInterval:2];

方法二:

[self performSelector:@selector(delayMethod) withObject:nil afterDelay:15];

37、系统风火轮:

[UIApplication sharedApplication]networkActivityIndicatorVisible = NO; //隐藏

38、//didSelectRowAtIndexPath:方法里面找到当前的Cell

AssessMentCell cell = [tableView cellForRowAtIndexPath:indexPath];

39、navigation上返回按钮的颜色以及返回按钮后面文字去掉

//返回按钮后边文字去掉

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)

forBarMetrics:UIBarMetricsDefault];

//设置左上角返回按钮的颜色

selfnavigationControllernavigationBartintColor = UIColorFromRGB(0x666666);

40、lineBreakMode //设置文字过长时的显示格式

labellineBreakMode = NSLineBreakByCharWrapping;以字符为显示单位显

示,后面部分省略不显示。

labellineBreakMode = NSLineBreakByClipping;剪切与文本宽度相同的内

容长度,后半部分被删除。

labellineBreakMode = NSLineBreakByTruncatingHead;前面部分文字

以……方式省略,显示尾部文字内容。

labellineBreakMode = NSLineBreakByTruncatingMiddle;中间的内容

以……方式省略,显示头尾的文字内容。

labellineBreakMode = NSLineBreakByTruncatingTail;结尾部分的内容

以……方式省略,显示头的文字内容。

labellineBreakMode = NSLineBreakByWordWrapping;以单词为显示单位显

示,后面部分省略不显示。

我们做客户端的时候,有时会需要对客户端与服务器的时间进行同步,比如抢购活动、倒计时等。这时我们要考虑如何准备地与服务器的时间进行同步,同时防止用户本地的时间有误差时导致的问题。

为了实现以上需求,我们需要:

获取当前 Unix Time:

获取设备上次重启的 Unix Time:

时间校准:

iOS关于时间的处理

手机会通过网络获得正确的时间,并根据您所在的时区来更新时间。如果您使用的是华为手机,您可以根据需要,手动调整日期、时间、时区。

进入设置 > 系统和更新 > 日期和时间,按需设置。

1、自动获取或手动设置日期和时间

开启自动设置开关,手机将与当前网络上的时间同步。

或关闭自动设置开关手动调整日期和时间。

2、修改时区

开启自动设置开关,手机将与当前网络上的时区同步。

关闭自动设置开关您可以手动修改时区。

3、设置 12 小时制或 24 小时制

开启24小时制开关,时间将以 24 小时格式显示。

关闭24小时制开关,时间将以 12 小时格式显示。

- (int)intervalSinceNow: (NSString ) theDate\x0d\{\x0d\\x0d\NSDateFormatter date=[[NSDateFormatter alloc] init];\x0d\[date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];\x0d\NSDate d=[date dateFromString:theDate];\x0d\\x0d\NSTimeInterval late=[d timeIntervalSince1970]1;\x0d\\x0d\\x0d\NSDate dat = [NSDate dateWithTimeIntervalSinceNow:0];\x0d\NSTimeInterval now=[dat timeIntervalSince1970]1;\x0d\NSString timeString=@"";\x0d\\x0d\NSTimeInterval cha=now-late;\x0d\\x0d\if (cha/86400>1)\x0d\{\x0d\timeString = [NSString stringWithFormat:@"%f", cha/86400];\x0d\timeString = [timeString substringToIndex:timeStringlength-7];\x0d\return [timeString intValue];\x0d\}\x0d\return -1;\x0d\}\x0d\\x0d\上面的例子只是计算相差了几天\x0d\\x0d\当然可以计算其他数值\x0d\cha/36001&&cha/86400回答于 2022-11-16

我们在登录一个手机app时,每次输入的账户密码都是固定的。但是这样呢如果通过网络请求发送时,容易被拦截获取到账号密码。其中有一种加密的方式,就是使用动态的密码进行登录。这样保密性会高很多。动态密码,实际上是先将普通密码加密再加上一段会变化的数据(比如时间)再进行一次加密。这样我们每次获得的密码部分都是不同的。这就是动态密码的大概含义——理解の。

动态密码: 相同的密码明文,每次发送到服务器,密码都不同 ---时间戳密码!

时间间隔越小,密码安全性越高! 一分钟/将军令/U盾

动态密码,我们需要事先和后台约定好对数据的加密方式。

1、创建字符串对象存放服务器拿到的私钥。

2、对密码和私钥进行第一次加密

3、获取当前的时间,并对时间按照一定的格式进行处理

4、将第一次加密后的密码和经过处理的时间进行拼接

5、拼接后再进行一次加密,然后可以返回当前得到的字符串。

从参数中获取原始密码 password ,返回加密后的

方法如下:

工具:iPhone 8

*** 作系统:iOS 1441

程序:设置201

1、以苹果8为例,打开苹果手机主界面,点击设置。

2、在设置列表,找到并点击通用,如下图。

3、在通用列表,点击日期与时间,如下图。

4、找到顶部的24小时制,如下图。

5、点击24小时制右侧,将使用24小时制后方的开关打开。

6、回到主界面,手机的时间就显示为24小时制。

以上就是关于iOS开发中遇到的小问题-----总结全部的内容,包括:iOS开发中遇到的小问题-----总结、iOS 客户端与服务端做时间同步、手机的时间怎么设置啊等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9506986.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存