开发中遇到的问题

1.键盘透明

1
textField.keyboardAppearance = UIKeyboardAppearanceAlert;

2.状态栏的网络活动风火轮是否旋转

1
[UIApplication sharedApplication].networkActivityIndicatorVisible,默认值是NO。

3.NSMutableAttributedString 行间距、段落间距

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:dLabelString];  
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

//行间距
[paragraphStyle setLineSpacing:5.0];
//段落间距
[paragraphStyle setParagraphSpacing:10.0];
//第一行头缩进
[paragraphStyle setFirstLineHeadIndent:15.0];
//头部缩进
//[paragraphStyle setHeadIndent:15.0];
//尾部缩进
//[paragraphStyle setTailIndent:250.0];
//最小行高
//[paragraphStyle setMinimumLineHeight:20.0];
//最大行高
//[paragraphStyle setMaximumLineHeight:20.0];

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [dLabelString length])];
[dLabel setAttributedText:attributedString];

4.跳转storyBoard

1
2
3
4
5
6
7
8
9
10
11
12
1.获取第一个视图storyBoard
/* 加载名为storyboardName的Storyboard */
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];

/* 获取storyboard的InitialViewController 即根控制器*/
FirstViewController *vc = [storyboard instantiateInitialViewController];
其中UIViewController可以根据当前视图进行替换,替换成StoryBoard对应的视图类,然后选择跳转方式
2.获取第二个视图storyboard的某个视图控制器的时候使用
SecondViewController *VC= [storyboard instantiateViewControllerWithIdentifier:@"NewVC”];(这个过程需要在StoryBoard中设置目标视图的Custom Class和StoryBoard ID)
//跳转事件的实现
在第一个视图添加按钮跳转到第二个视图
[self.navigationController pushViewController:VC animated:YES];(第一个视图是带有导航栏的)

5.用代码使程序转向设置页面:

1
2
NSURL *url=[NSURL URLWithString:@"prefs:root=WIFI"];//转向->"设置wifi"页面
[[UIApplication sharedApplication] openURL:url];

6.系统判断

1
2
3
4
5
6
7
8
9
10
11
#define isOperatingSystemAtLeastVersion(majorVersion, minorVersion, patchVersion)[[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: (NSOperatingSystemVersion) {
majorVersion,
minorVersion,
patchVersion
}]

if (isOperatingSystemAtLeastVersion(11, 0, 0)) {
//using new API
} else {
//using deprecated API
}

7. web Cookies 每次退出应用都被清除解决方法( 用于实现自动登录 )https://www.jianshu.com/p/19a053e37c53

1
2
3
4
5
6
7
8
9
10
11
12
13
NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray<NSHTTPCookie *> *cookies = [cookieStorage cookiesForURL:[NSURL URLWithString:baseUrl]];
NSMutableArray<NSDictionary *> *propertiesList = [[NSMutableArray alloc] init];
[cookies enumerateObjectsUsingBlock:^(NSHTTPCookie * _Nonnull cookie, NSUInteger idx, BOOL * _Nonnull stop) {
NSMutableDictionary *properties = [[cookie properties] mutableCopy];
//将cookie过期时间设置为一年后
NSDate *expiresDate = [NSDate dateWithTimeIntervalSinceNow:3600*24*30*12];
properties[NSHTTPCookieExpires] = expiresDate;
//下面一行是关键,删除Cookies的discard字段,应用退出,会话结束的时候继续保留Cookies
[properties removeObjectForKey:NSHTTPCookieDiscard];
//重新设置改动后的Cookies
[cookieStorage setCookie:[NSHTTPCookie cookieWithProperties:properties]];
}];
-------------本文结束感谢您的阅读-------------
``` ```