代码块

1:手势:

    //单击
    UITapGestureRecognizer * tapGestuer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction)];
    
    tapGestuer.delegate  =self;
    [self.view addGestureRecognizer:tapGestuer];
    
    //左轻扫手势
    UISwipeGestureRecognizer * leftSwipeGesture  =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeGestureAction)];
    leftSwipeGesture.delegate = self;
    leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:leftSwipeGesture];
    
    //右轻扫手势
    UISwipeGestureRecognizer * rightSwipeGuesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeGuestAction)];
    rightSwipeGuesture.delegate = self;
    rightSwipeGuesture.direction  =UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:rightSwipeGuesture];

2:point 是否在一个标准范围内

/* Return true if `point' is contained in `rect', false otherwise. */

CG_EXTERN bool CGRectContainsPoint(CGRect rect, CGPoint point)
    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);


    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.view addGestureRecognizer:tap];

- (void)tapAction:(UITapGestureRecognizer *)tap{

    CGPoint point = [tap locationInView:self.view];
//    BOOL isTapMiddle = CGRectContainsPoint(CGRectMake(self.view.frame.size.width/2 -50, self.view.frame.size.height/2 -50, 100, 100), point);
    
    BOOL isTapMiddle = CGRectContainsPoint(CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 - 160), point);
    if (isTapMiddle) {
        self.pageMenuView.hidden = !self.pageMenuView.hidden;
    }
}


3: 将html文字显示到uitextView里

      
        NSString * contentStr = [NSString stringWithFormat:@"%@<br>%@<br>%@<br>%@%@<br>",BgTitle,fangContent,strFan1,tanslationStr,gist];
        
        NSAttributedString * attributedString = [[NSAttributedString alloc]initWithData:[contentStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{
                                                                                                                                                         NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSFontAttributeName:                                                                                [BookManager sharedInstance].contentFont
                                                                                                                                                         } documentAttributes:nil error:nil];
        self.contentAll = contentStr;
        self.textView.attributedText =attributedString;

4: block回掉,异步执行回到主线程,fmdb数据库

.h文件

声明block:
typedef void(^CompleteBlock)(NSMutableArray * dataArray, NSError *error);


.m文件

+ (instancetype)sharedQueue{
    
    
    static VFMDataManager * manager = nil;
    static dispatch_once_t  onceToken = 0;
    dispatch_once(&onceToken, ^{
        manager = [[VFMDataManager alloc] initWithQueue];
    });
    return manager;
}

- (instancetype)initWithQueue{
    self = [super init];
    if (self) {
        [self createDatabaseQueue];
    }
    return self;
}

- (void )dxbookSectionWithBookID:(NSString *)bookID
                 completionBlock:(CompleteBlock)block{
    [SVProgressHUD show];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [_dataBaseQueue inDatabase:^(FMDatabase *db) {
            NSMutableArray *array = [[NSMutableArray alloc]init];
            
            NSString *sql = @"select chapter_id,chapter_zh_name,sj from chapter_akdx orderby where book_id = ?";
            
            FMResultSet *result=[db executeQuery:sql,bookID];
            while ([result next]) {
                NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
                [dic setValue:[result stringForColumn:@"chapter_id"] forKey:@"chapter_id"];
                [dic setValue:[result stringForColumn:@"chapter_zh_name"] forKey:@"chapter_zh_name"];
                [dic setValue:[result stringForColumn:@"sj"] forKey:@"sj"];
                
                [array addObject:dic];
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                block(array,nil);
                [SVProgressHUD dismiss];
            });
            
        }];
        
    });
    
}

- (void)createDatabaseQueue{
    NSString * documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"vedabooks.db"];
    NSLog(@"-----%@",filePath);
    if(![fileManager fileExistsAtPath:filePath]) //如果不存在
    {
        NSLog(@"vedabooks.db is not exist");
        NSString *dataPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/vedabooks.db"];//获取程序包中相应文件的路径
        NSError *error;
        if([fileManager copyItemAtPath:dataPath toPath:filePath error:&error]) //拷贝
        {
            NSLog(@"copy vedabooks.db success");
        }
        else
        {
            NSLog(@"%@",error);
        }
    }
    
    _dataBaseQueue = [[FMDatabaseQueue alloc]initWithPath:filePath];
}

//获取document目录并返回数据库目录
- (NSString *)dataFilePath
{
    //方法1
    //     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    //     NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"vedabooks.db"];
    
    
    NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
    NSString * path = [documentsDirectory stringByAppendingPathComponent:@"vedabooks.db"];
    // NSLog(@"iapChinaPurchase-->%@",path);
    return path;
}

5:联合查询:from sections2 a,:---》将sections2映射为表a

                NSString *sqlbook1 = [NSString stringWithFormat:@"select a.*,b.book_zh_name,b.book_en_name,c.chapter_zh_name,c.chapter_en_name from sections2 a,vd_books b,chapter c where a.book_id=b.book_id and a.chapter_id=c.chapter_id and a.book_id=1 and (a.yw_zh2 like '%%%@%%' or a.yw_en2 like '%%%@%%') order by a.book_id, a.chapter_id,(a.section_id+0)",text,text];
                FMResultSet *result=[db executeQuery:sqlbook1];
                while ([result next]) {
                    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
                    [dic setValue:[result stringForColumn:@"book_zh_name"] forKey:@"book_zh_name"];
                    [array addObject:dic];
                }


6:设置指定位置文字的颜色

    NSString * textStr =@"项目管理师是指掌握项目管理原理、技术、方法和工具,参与或领导启动、计划、组织、执行、控制和收尾过程的活动,确保项目能在规定的范围、时间、质量与成本等约束条件下完成既定目标的人员。";
    NSString * tagStr = @"项目";
    NSMutableAttributedString * detial = [[NSMutableAttributedString alloc] initWithString:textStr
                                          ];
    [detial addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[textStr rangeOfString:tagStr]];// 关键步骤,设置指定位置文字的颜色

    
    self.labels.lineBreakMode = NSLineBreakByWordWrapping;
    self.labels.numberOfLines = 0;
    self.labels.attributedText = detial;

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值