- 图片压缩代码
在图片上传过程中,照相机拍摄的图片太大,无法直接上传到服务器,需要先进行压缩。
/*
1. pngData是用于上传的二进制流
2. _imageToUpload是拍摄的照片文件,UIImage格式
3. 0.3为float型,压缩大小
4. kCompressionQuality不要调太低,会出现有时显示出黑图的异常情况 一般 0.3-0.7之间。
*/
float kCompressionQuality = 0.3;
NSData *pngData = UIImageJPEGRepresentation(_imageToUpload, kCompressionQuality);
- 代码实现边框线条的按钮
UIButton *uploadButton = [[UIButton alloc]init];
uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
uploadButton.backgroundColor = [UIColor whiteColor];
CGRect buttonFrame = CGRectMake(20, 376 + 20, self.view.frame.size.width - 40, 30);
uploadButton.frame = buttonFrame;
[uploadButton.layer setMasksToBounds:YES];
uploadButton.layer.cornerRadius = 10;
uploadButton.layer.borderWidth = 1.0;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 0.0, 120.0/255.0, 1.0, 1.0 });
UIColor *systemBlue = [UIColor colorWithRed:0.0 green:120.0/255.0 blue:1.0 alpha:1.0];
uploadButton.layer.borderColor = colorref;
//uploadButton.backgroundColor = [UIColor whiteColor];
[uploadButton setTitle:@"确认上传" forState:UIControlStateNormal];
[uploadButton setTitleColor:systemBlue forState:UIControlStateNormal];
[uploadButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[uploadButton addTarget:self action:@selector(didUpload) forControlEvents:UIControlEventTouchUpInside];
uploadButton.hidden = YES;
[self.view addSubview:uploadButton];
效果图:
- 分享一个好用的查询快递的连接: 快递查询