美文网首页
开发小技巧

开发小技巧

作者: 再近不过信仰 | 来源:发表于2019-06-02 15:51 被阅读0次
    系统自带的label自适应宽度
    [self.titleLab setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    

    表格中刷新指定分区,UITableViewRowAnimationFade淡入淡出动画,[str integerValue]分区下标

    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[str integerValue]]withRowAnimation:UITableViewRowAnimationFade];
    

    iOS7之后使用boundingRectWithSize计算text高度时,切记要取最大值的整数,例如13.33取14
    可以使用ceil函数取整(ceil(abSize.height))

    - (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
    {
        return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
    }
    
    使用masonry创建控件后,如果想要获取当个控件的属性值,例如宽和高使用
    NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:_questionLab];
    进行遍历后可获取
    
    iOS8之后可以不用实现表格的代理方法但需设置
        self.tableView.estimatedRowHeight = rowHeight;
        self.tableView.rowHeight = UITableViewAutomaticDimension;
    

    Debug下运行没有问题,切换成Release之后发生崩溃,仔细检查之后发现是某个值在两种状态下不一样,在给变量进行初始赋值之后就没有问题了,所以 :一定要养成不管是任何变量,都先进行初始化的习惯!!!

    使用fileURLWithPath创建出来的URL会自动加上协议头file://;
    而使用URLWithString创建的URL,与原有的字符串一模一样;
    所以在访问本地资源的时候,不要犹豫,fileURLWithPath是你的首选.不过要注意去掉字符串中的协议头!

    "OBJC_METACLASS$_AFHTTPSessionManager", referenced from:
    问题已得到解决,解决方法如下:~/Library/Developer/Xcode/DerivedData 关掉xcode,删掉DerivedData这个文件夹里的全部东西 然后重新打开项目clean>build

    刷新表格之后上下无规则移动解决方法:
    _tableView.estimatedRowHeight = 0;
    _tableView.estimatedSectionHeaderHeight = 0;
    _tableView.estimatedSectionFooterHeight = 0;
    
    如果按钮被覆盖,响应不了事件可重写hitTest方法: _optionD:被覆盖的按钮
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        CGPoint redBtnPoint = [self convertPoint:point toView:_optionD];
        if ([_optionD pointInside:redBtnPoint withEvent:event]) {
            return _optionD;
        }
        //如果希望严谨一点,可以将上面if语句及里面代码替换成如下代码
        //UIView *view = [_optionD hitTest: redBtnPoint withEvent: event];
        //if (view) return view;
        return [super hitTest:point withEvent:event];
    }
    
    // 重写setFrame
    - (void)setFrame:(CGRect)frame{
        frame.origin.x += 10;
        frame.origin.y += 10;
        frame.size.height -= 10;
        frame.size.width -= 20;
        [super setFrame:frame];
    }
    
    // 重写setFrame方法,为Cell添加阴影偏移
    - (void)setFrame:(CGRect)frame
    {
        static CGFloat margin = 15;
        frame.size.height -=margin;
        //阴影偏移效果 - wsx注释
        self.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        self.layer.shadowOffset = CGSizeMake(4, 6);
        self.layer.shadowOpacity = 0.8f;
        [super setFrame:frame];
    }
    
    /**
    * 功能:UILabel 字体设置
    */   
      label.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];//加粗
      label.font = [UIFont fontWithName:@"Helvetica-Oblique" size:20];//加斜
      label.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];//又粗又斜
    
    //获取导航栏+状态栏的高度
    #define getRectNavAndStatusHight  self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height
    
    // 取消表格点击状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    // cell点击不变色
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    
    #pragma mark - 将tableView索引区域背景变为透明
        if ([_tableView respondsToSelector:@selector(setSectionIndexColor:)]) {
            _tableView.sectionIndexBackgroundColor = [UIColor clearColor];
            _tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
        }
    

    git clone url(项目仓库地址) //克隆一个远程仓库,就是在本地建立一个新的项目。
    git pull origin master //如果已经有一个项目,通过这条指令可以直接更新该项目
    提交修改的项目,步骤如下:
    git status
    git add -A
    git commit -a -m "填写修改的内容"
    git push -u origin master

    图片切圆

     // 创建图片框
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
        // 添加图片
        imageView.image = [UIImage imageNamed:@"104.jpg"];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:imageView.bounds.size];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        //设置大小
        maskLayer.frame = imageView.bounds;
        //设置图形样子
        maskLayer.path = maskPath.CGPath;
        imageView.layer.mask = maskLayer;
        [self.view addSubview:imageView];
    

    页眉动画

    // 淡入淡出
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[str integerValue]]withRowAnimation:UITableViewRowAnimationFade];
    
    #pragma mark - 设置输入框下边框
    - (void)setTextFieldCALayer:(UITextField *)textField
    {
        CALayer *bottomBorder = [CALayer layer];
        bottomBorder.backgroundColor = [UIColor orangeColor].CGColor;
        bottomBorder.frame = CGRectMake(0.0f, textField.frame.size.height - 1, textField.frame.size.width, 1.0f);
        bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
        [textField.layer addSublayer:bottomBorder];
    }
    
    跳转App Store评分。 若检查更新,将URL地址改为"itms-apps://itunes.apple.com/app/id%@"
    评分:
    #define APPID @"1485844799"
    NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",APPID];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
    

    相关文章

      网友评论

          本文标题:开发小技巧

          本文链接:https://www.haomeiwen.com/subject/bvqspftx.html