Skip to content

Instantly share code, notes, and snippets.

View yuxiangq's full-sized avatar
🎯
Focusing

Yuxiang yuxiangq

🎯
Focusing
  • ThoughtWorks
  • Chengdu
View GitHub Profile
@yuxiangq
yuxiangq / CreateEKEventDemo.m
Last active May 22, 2016 15:15
创建EKEvent
...
- (void)createEvent {
EKEvent *event = [EKEvent eventWithEventStore:self.es];//
//可以设置event的相关属性,title表示标题,notes表示备注,-(void)addAlarm:(EKAlarm *)alarm;方法可以添加提醒时间...
[self.es saveEvent:event span:EKSpanThisEvent error:nil];//这个时候会生成Event对应的唯一Identifier。
/*EventStore还支持批量写入Event。*/
/*使用-(BOOL)saveEvent:(EKEvent *)event span:(EKSpan)span commit:(BOOL)commit error:(NSError **)erro;方法,commit设为NO*/
/*然后再调用[EKEventStore commit:]一次性提交所有新增*/
}
@yuxiangq
yuxiangq / EventKitDemo.m
Last active May 22, 2016 14:50
EventKit介绍
#import <EventKit/EventKit.h>
...
- (void)createEKEventStore {
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];//获取日历状态权限
if(status != EKAuthorizationStatusAuthorized) {
//没有获取权限则请求权限
self.es = [[EKEventStore alloc] init];
[self.es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted
,NSError * _Nullable error) {
if(granted) {
@yuxiangq
yuxiangq / demo.m
Last active April 18, 2016 16:18
iOS中的泛型
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) NSMutableArray<NSNumber*> *numbersArray;
@end
@implementation ViewController
@yuxiangq
yuxiangq / demo.m
Created March 4, 2016 16:44
funnelChartViewDemo
#import "FunnelChart.h"
- (void)viewDidLoad {
[super viewDidLoad];
//初始化数据对象
FunnelChartModel *model1 = [FunnelChartModel new];
model1.value = 10.f;
model1.color = [UIColor redColor];
@yuxiangq
yuxiangq / demo.m
Last active May 19, 2017 14:20
NSOperationQueue 实现串行请求
//用了表示是否有异步请求正在执行
@property (assign, atomic) BOOL excuting;
@property (strong, nonatomic) NSArray *datasArray;
@property (strong, nonatomic) NSOperationQueue *operationQueue;
- (void)ViewDidLoad {
[super viewDidLoad];
self.excuting = NO;
self.operationQueue = [[NSOperationQueue alloc] init];
@yuxiangq
yuxiangq / demo.m
Last active February 19, 2016 14:18
递归 请求队列实现
//仅列出关键代码
@property (strong, nonatomic) NSArarry *datasArray;
- (void)beginUploadData {
[self uploadDataToServer:self.datasArray[0] index:0];
}
- (void)uploadDataToServer:(id)data index:(NSUInteger)index {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
@yuxiangq
yuxiangq / gist:6c282d9899fe28fe59e4
Last active August 29, 2015 14:19
prototypeCustomCell的初始化
//仅展示部分代码
@interface ViewController ()
/**
* 原型cell
*/
@property (strong,nonatomic) CustomCell *prototypeCustomCell;
/**
* 数据源
-(void)p_updateConstraints{
[self.contentView removeConstraints:self.contentView.constraints];
NSDictionary *views=@{@"contentLabel":self.contentLabel};
NSMutableArray *constraints=[NSMutableArray array];
//设置水平约束
[constraints addObjectsFromArray:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-5-[contentLabel]-5-|"
options:0
metrics:nil
views:views]];
@yuxiangq
yuxiangq / gist:96c5ffeb2ab9d718a33e
Last active August 29, 2015 14:18
customCell的初始化控件方法
-(void)initControls{
_contentLabel=[UILabel new];
_contentLabel.translatesAutoresizingMaskIntoConstraints=NO;
_contentLabel.numberOfLines=0;
_contentLabel.lineBreakMode=NSLineBreakByWordWrapping;
[self.contentView addSubview:_contentLabel];
}
@yuxiangq
yuxiangq / gist:71a2ac1dabac7b4fa556
Last active August 29, 2015 14:11
NumberField的用法
//...
-(void)viewDidLoad{
[super viewDidLoad];
NumberField *numberField=[[NumberField alloc] initWithFrame:CGRectMake(100, 100, 120, 44)];
numberField.placeholder=@"只能输入数字";
//设置精度,长度为10,小数点位数为4的苏子。
numberField.numeric=CGNumeric(10, 4);