Skip to content

Instantly share code, notes, and snippets.

View 0oneo's full-sized avatar
😃
Go Li

0oneo 0oneo

😃
Go Li
  • 阿里本地生活
  • Shanghai
View GitHub Profile
@0oneo
0oneo / set view's background
Created November 18, 2013 16:04
set background of a view, see link
UIImage *image = [UIImage imageNamed:@"name.png"];
view.layer.contents = (id) image.CGImage;
// 如果需要背景透明加上下面这句
view.layer.backgroundColor = [UIColor clearColor].CGColor;
@0oneo
0oneo / NSDateFormatter's right usage
Created October 12, 2013 08:20
NSDateFormatter is not thread safe
// test code that generate the error
for (int i = 0; i < 1000; i++) {
NSDate *date= [NSDate date];
NSString *queueName = [NSString stringWithFormat:@"queue%i", i];
dispatch_queue_t testqueue = dispatch_queue_create([queueName cStringUsingEncoding:NSUTF8StringEncoding], NULL);
dispatch_async(testqueue, ^{
NSDateFormatter *ndf = [BXAppDelegate dateFormatter];
DDLogInfo(@"%@", [ndf stringFromDate:date]);
});
}
// pls check http://t.cn/z8ncg24
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[weakself.tableView reloadData];
}];
[weakself.tableView beginUpdates];
[weakself.tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
[weakself.tableView endUpdates];
[CATransaction commit];
NSArray *images = @[@"http://example.com/image1.png",
@"http://example.com/image2.png",
@"http://example.com/image3.png",
@"http://example.com/image4.png"];
dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue",NULL);
for (NSString *urlString in images) {
dispatch_async(imageQueue, ^{