zoukankan      html  css  js  c++  java
  • iOS小技巧2

    这段代码是实现了类似QQ空间"我的空间"里面的圆形头像
        //圆形的头像
        UIImageView * headImage = [[UIImageView alloc]initWithFrame:CGRectMake(100, 300, 120, 120)];
        headImage.backgroundColor = [UIColor grayColor];
        headImage.image = [UIImage imageNamed:@"headimage.jpg"];
        headImage.clipsToBounds = YES;
        headImage.layer.cornerRadius = headImage.bounds.size.width/2;
        headImage.layer.borderWidth = 2;
        headImage.layer.borderColor = [UIColor yellowColor].CGColor;
        [self.view addSubview:headImage];
    创建具有中划线的文字
    
     NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
        
        NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:@"价格:40" attributes:attribtDic];
    label.attributedText = attribtStr
    在使用target-action模式的时候, 在ARC模式下会有内存提示. 用这几句代码可以消除提示. (强迫症福音)
    #       pragma clang diagnostic push
    #       pragma clang diagnostic ignored "-Warc-performSelector-leaks"
                [_target performSelector:_action withObject:self];
    #       pragma clang diagnostic pop
    设置UISearchBar的背景颜色
    
    今天用到UISearchBar,之前网上提供的方法已经不能有效的去除掉它的背景色了,修改背景色方法如下:
     mySearchBar.backgroundColor = RGBACOLOR(249,249,249,1);
        mySearchBar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:mySearchBar.bounds.size];
    
    //取消searchbar背景色
    - (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
    {
        CGRect rect = CGRectMake(0, 0, size.width, size.height);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        return image;
    }
    ios tableView上面空出20个像素的解决办法
    
    tableView上面多出来20个像素,是因为自动布局的缘故,设置一下属性就可以解决问题
    self.edgesForExtendedLayout = UIRectEdgeNone;
    下面代码解决cell重用,贴出来方便下次使用
     //解决cell重用
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
  • 相关阅读:
    jdk1.8 LongAdder源码学习
    linux 下 vi 文本编辑如何复制一行粘贴删除一行数据
    远程调试
    本机与远程主机指定端口的网络是否连通
    自定义弹窗
    Windows查看占用端口的进程及其对应的应用程序并关闭之
    超实惠:99元阿里云服务器1核2G内存40G硬盘(SSD)
    Java显式锁学习总结之六:Condition源码分析
    Maven使用国内镜像
    深入理解读写锁—ReadWriteLock源码分析
  • 原文地址:https://www.cnblogs.com/Ganggang888/p/5253594.html
Copyright © 2011-2022 走看看