小功能分享

删除多余cell
- (void)setExtraCellLineHidden: (UITableView *)tableView {
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [view release];
}
 
 
 
一键换肤
[[UITabBar appearance] setTintColor:_array[indexPath.item]];
    [[UINavigationBar appearance]setBarTintColor:_array[indexPath.item]];
    [[UITabBar appearance] setBackgroundColor:_array[indexPath.item]];
 
 
 
夜间模式
-(void)handleNightSwitch:(UISwitch *)nigetSwitch{
 
    if (nigetSwitch.on) {
        self.view.window.alpha = 0.4;
        NSLog(@"打开夜间模式");
    }else{
        self.view.window.alpha = 1.0;
        NSLog(@"关闭夜间模式");
    }
}
所有界面都能通过
[UIApplication sharedApplication].keyWindow
 
 
修剪图片
NSInteger ImgWidth = [model.imgWidth integerValue];
     NSInteger ImgHeight = [model.imgHeight integerValue];
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        CGImageRef cgRef = image.CGImage;
        CGImageRef imageRef1 = CGImageCreateWithImageInRect(cgRef, CGRectMake(0, 0, ImgWidth, ImgHeight));
 
        CGImageRef imageRef2 = CGImageCreateWithImageInRect(cgRef, CGRectMake(0, 0, ImgWidth, ImgWidth * 0.6));
 
        if (ImgHeight < ImgWidth * 0.6) {
            UIImage *thumbScale = [UIImage imageWithCGImage:imageRef1];
            self.imgView.image = thumbScale;
        }else{
            UIImage *thumbScale = [UIImage imageWithCGImage:imageRef2];
            self.imgView.image = thumbScale;
        }
    }];
 
 
搜索文本改变时
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
    [self.searchData removeAllObjects];
 
    if (searchController.searchBar.text) {
        for (int i = 0; i < searchController.searchBar.text.length; i++) {
            NSRange range = NSMakeRange(i, 1);
            NSString *subString = [searchController.searchBar.text substringWithRange:range];
            const char *cString = [subString UTF8String];
            //判断输入的是汉字还是字母
            if (strlen(cString) == 3) {
                NSLog(@"输入的是汉字");
                NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"self.name CONTAINS %@",searchController.searchBar.text];
                self.searchData = [[self.allCitysArr filteredArrayUsingPredicate:searchPredicate] mutableCopy];
            } else if (strlen(cString) == 1) {
                NSLog(@"输入的是字母");
 
                NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"self.pinyin CONTAINS %@",searchController.searchBar.text];
                self.searchData = [[self.allCitysArr filteredArrayUsingPredicate:searchPredicate] mutableCopy];
            }
        }
    }
 
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
    });
}
 
图片模糊效果
self.groundImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [self addSubview:_groundImage];
 
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectivew = [[UIVisualEffectView alloc]initWithEffect:blur];
    effectivew.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [_groundImage addSubview:effectivew];
 
sd_setImageWithURL:
 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {}
block里的image就是原始的图片可以用
CGFloat imageWidth = image.size.width;
CGFloat imageHeight = image.size.height;
取到原始宽高
 
storyboard:
Leading Edges:左对齐
Trailing Edges:右对齐
Top Edges:上对齐
Bottom Edges:下对齐
Horizontal Centers:水平中心对齐
Vertical Centers:竖向中心对齐
Baselines:基线对齐
Horizontal Center in Container:对齐容器中的水平中心
Vertical Center in Container:对齐容器中的竖向中心
 
屏幕纵横比(Aspect Ratio): 显示设备中显示图像的横向尺寸与纵向尺寸的比例,最常见的为4:3,目前的高清晰度电视和一些新型显示设备采用了16:9。
 
 
//设置文字的下划线
    NSString *oldPrice = tryList.price;
    if (IOS7) {
        NSString *lineString = [NSString stringWithFormat:@"¥%@",oldPrice];
 
        NSUInteger length = [oldPrice length];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:lineString];
        [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:NSMakeRange(0,length+1)];//画线
 
        [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, length+1)];
        [self.priceLabel setAttributedText:attri];
    }
 
//设置文字上的线
NSUInteger length = [oldPrice length];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:lineString];
        [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:NSMakeRange(0,length+1)];
 
        [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, length+1)];//线的颜色
        [self.priceLabel setAttributedText:attri];
 
 
 
点击return回收键盘的TextField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
 
点击空白回收键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
            [textField resignFirstResponder];
           // self.view endEditing:YES;//回收所有键盘
}
 
 
 在TableViewController中调用cell 
 FirstTableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
 
 弹框
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"恭喜注册成功" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            [alertController addAction:action];
            [self presentViewController:alertController animated:YES completion:nil];
 
 
 
posted @ 2016-03-10 08:58  莫念莫忘  阅读(80)  评论(0编辑  收藏  举报