旋转UILabel

一、 简介

1, 先看一下,我们要实现的效果:

图1

图2

就是上图中的 “剩余3天” 和 “延期” 这种效果,这种是一个倾斜的控件, 如果文字是固定的一种或者多种,可以通过图标的方式来设置,但是,如果倾斜的文字内容前端无法确定,需要接口返回,那么,这种效果该怎么实现呢?

2, 设想,如果使用UILabel这个控件,设置背景色,文字颜色,然后通过控件的transform方法(设置锚点)旋转一下,能否?

Read More

IOS扫码登录

很多的网站,或者桌面应用都用了手机扫码登录的功能,现在,我们了解一下,扫码登陆的大致过程:

  1. 浏览器输入网站地址,展示登录二维码信息等。
  2. 手机通过扫描二维码,确认登录。
  3. 网页或者桌面应用检测到手机允许登录,生成用户信息登录成功。
Read More

IOS指纹登录

一、简介

TouchID指纹识别是iPhone 5S设备中增加的一项重大功能.苹果的后续移动设备也相继添加了指纹功能,在实际使用中还是相当方便的,比如快捷登录,快捷支付等等.系统提供了相应框架,使用起来还是比较方便的.使用LAContext对象即可完成指纹识别,提高用户体验.

指纹登录,可以分解为两个流程:

  1. 用户名密码登录成功之后,开启指纹登录。
  2. 指纹登录开启后,下次使用指纹登录。
Read More

ios原生API文件上传(NSURLSession)

一、 简介

以前,在上传文件时,可以使用NSURLConnection类,由于这个类已经过期,只支持到ios9, 所以,本节使用NSURLSession来上传文件。

NSURLSession针对下载/上传等复杂的网络操作提供了专门的解决方案,针对普通、上传和下载分别对应三种不同的网络请求任务:NSURLSessionDataTask, NSURLSessionUploadTask和NSURLSessionDownloadTask 。创建的task都是挂起状态,需要resume才能执行。

二、使用

1、引入框架和定义编码宏

1
2
3
#import <MobileCoreServices/MobileCoreServices.h>

#define GMEncode(str) [str dataUsingEncoding:NSUTF8StringEncoding]

2、编写上传方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-(void)upload:(NSString *)filePath params:(NSDictionary *)params{
NSURL *url = [NSURL URLWithString:@"http://192.168.1.103:9088/up/upload"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];

//分隔符
NSString *boundary = [self generateBoundaryString];

//设置ContentType
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];

//获取body体数据
NSString *fieldName = @"CustomFile";
NSData *bodyData = [self createBodyWithBoundary:boundary parameters:params filePath:filePath fieldName:fieldName];

NSURLSessionTask *task = [[NSURLSession sharedSession] uploadTaskWithRequest:request fromData:bodyData completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"error : %@", error);
return;
}
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"上传返回结果 : %@", result);
}];

[task resume];
}

Read More

IOS苹果登录(sign in with apple)

一、 sign in with apple 简介

苹果官方介绍:

1
2
3
4
5
6
7
8
9
10
11
12
The fast, easy way to sign in to apps and websites.

Sign In With Apple 是一种在app 和网站上快速、容易登录的方式。

Sign In with Apple makes it easy for users to sign in to your apps and websites using their Apple ID.
Instead of filling out forms, verifying email addresses, and choosing new passwords, they can use
Sign In with Apple to set up an account and start using your app right away. All accounts are protected
with two-factor authentication for superior security, and Apple will not track users’ activity in your app or website.

对于用户来说,Sign In With Apple 使他们可以使用Apple ID容易地登录apps和网站。
而不需要填写表单,验证邮件,选择新密码。用户可以使用Sign In With Apple 创建新用户并立即可以开始使用你的app。
为了提高安全性,双重因子验证保护了帐号的安全性。而且Apple 不会跟踪用户在app 和网站的行为信息。

注: 如果开发者使用了第三方登录,那必须也得使用苹果登录,这是苹果官方的硬性要求。如果没有使用第三方登录,开发者是可以不使用苹果登录的。

集成步骤:

Read More