1.
当进行继承的时候,需要实现下父类的方法,例如[super layoutSubViews]
。(在label preference中,继承的UIButton没有写[super layoutSubViews]
时候,titleLabel显示不出来)
2.
afn图片上传时,由于我们服务器不仅仅要文件上传,还要key和文件名一一对应,[formData appendPartWithFileData:obj name:[NSString stringWithFormat:@"pic%d",((int)idx+1)] fileName:[NSString stringWithFormat:@"pic%d.png",((int)idx+1)] mimeType:@"image/jpeg"];
这里的name 要和字典里的Key一一对应,不然服务器没办法识别,略坑啊~
3.图片进行圆角设置
1.最简单的的方法就是masksToBounds
。
2.用image进行剪切,得到一张新的image,方法如下:
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextAddEllipseInRect(ctx, rect);
CGContextClip(ctx);
[image drawInRect:rect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
return newImage;
当你使用SDWebImage获取图片,然后再进行剪切的时候,如果你是这样写的:
sd.png这个时候可能是看不到效果的,因为sd获取到的图片是异步线程的,此时block返回的image还没有设置,拿到的image是nil,所以是不行的。当然,你可以这样写:
sd2.png3.用calayer
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;