有没有办法将这些代码放在UIPasteboard中?
[TEXTFeild setLeftViewMode:UITextFieldViewModeAlways];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
imageView1.image = image;
TEXTFeild.leftView = imageView1;发布于 2016-01-16 06:41:50
若要共享用于黑板的图像,请使用以下内容:
//Method 1
UIImage * image=[UIImage imageWithContentsOfFile:@"FILE_PATH"];
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setImage:image];
//Method 2
NSData *imageData = UIImagePNGRepresentation(image);
[pasteboard setData:imageData forPasteboardType:(NSString *)kUTTypePNG];并在粘贴之前缩放图像:
CGFloat image_max_height = 1080;
CGFloat image_max_width = 1080;
UIImage *finalImage = image;
if (image.size.width>image_max_width || image.size.height>image_max_height) {
finalImage = [image imageByScalingAspectFitSize:CGSizeMake(image_max_width, image_max_height)];
}如果图像大于1080x1080,则此代码将图像缩小到1080 px1080px。
更新:该方法来自名为UIImage+SimpleResize的UIImage类别。把它添加到你的项目中,你就可以开始了。
https://stackoverflow.com/questions/34802131
复制相似问题