iOS开发的几个小问题(二)

  1. 图片压缩代码
    在图片上传过程中,照相机拍摄的图片太大,无法直接上传到服务器,需要先进行压缩。
/*
1. pngData是用于上传的二进制流
2. _imageToUpload是拍摄的照片文件,UIImage格式
3. 0.3为float型,压缩大小
4. kCompressionQuality不要调太低,会出现有时显示出黑图的异常情况 一般 0.3-0.7之间。 
*/
float kCompressionQuality = 0.3;
NSData *pngData = UIImageJPEGRepresentation(_imageToUpload, kCompressionQuality);
  1. 代码实现边框线条的按钮
    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];

效果图:这里写图片描述

  1. 分享一个好用的查询快递的连接: 快递查询
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值