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];
    }
原文地址:https://www.cnblogs.com/Ganggang888/p/5253594.html