2016-01-15 28 views
2

有沒有辦法將這段代碼放在UIPasteboardUIPasteboard代碼?

[TEXTFeild setLeftViewMode:UITextFieldViewModeAlways]; 

UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)]; 
imageView1.image = image; 
TEXTFeild.leftView = imageView1; 
+0

你的意思是粘貼在一些文本框或textview等?當然,爲什麼不呢,把它當成一條線。 – NSNoob

+0

我剛開始編程,那麼你會怎麼做? – James

+0

只需將整個代碼變成一個字符串即可。 – ShahiM

回答

0

要分享圖片到粘貼板使用這樣的:

//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)]; 
} 

此代碼縮放圖像到1080px X 1080px如果大於1080x1080。

更新:該方法來自UIImage類別,稱爲UIImage+SimpleResize。將它添加到你的項目中,你很好走。

+0

非常感謝您的幫助。 – James

+0

不客氣。請刪除重複的問題。 – ShahiM

+0

當然。沒問題。 – James