Browse Source

avatar on picker

Marino Faggiana 8 years ago
parent
commit
02ea46ae46

+ 1 - 1
Libraries external/XLForm/XL/Cell/XLFormPickerCell.m

@@ -98,7 +98,7 @@
 // TWS
 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
 {
-    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 44)];
+    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 50)];
     label.backgroundColor = [UIColor clearColor];
     label.textColor = [UIColor blackColor];
     label.font = [UIFont fontWithName:@"Helvetica" size:15.0];

+ 11 - 37
iOSClient/Settings/CCManageAccount.m

@@ -379,7 +379,7 @@
     if (!avatar)
         avatar = [UIImage imageNamed:@"avatarBN"];
     
-    avatar = [self imageWithImage:avatar scaledToSize:CGSizeMake(40, 40) isAspectRation:YES];
+    avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(40, 40) isAspectRation:YES];
     
     APAvatarImageView *avatarImageView = [[APAvatarImageView alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
         
@@ -437,42 +437,16 @@
     [self.tableView reloadData];
 }
 
-- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize isAspectRation:(BOOL)aspect {
-    if (!image) {
-        return nil;
-    }
-    //UIGraphicsBeginImageContext(newSize);
-    // In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
-    // Pass 1.0 to force exact pixel size.
-    CGFloat originRatio = image.size.width / image.size.height;
-    CGFloat newRatio = newSize.width / newSize.height;
-    
-    CGSize sz;
-    
-    if (!aspect) {
-        sz = newSize;
-    }else {
-        if (originRatio < newRatio) {
-            sz.height = newSize.height;
-            sz.width = newSize.height * originRatio;
-        }else {
-            sz.width = newSize.width;
-            sz.height = newSize.width / originRatio;
-        }
+/*
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    XLFormRowDescriptor *row = [self.form formRowAtIndex:indexPath];
+    
+    if ([row.tag isEqualToString:@"pickerAccount"]) {
+        // set background color in here
+        
     }
-    CGFloat scale = 1.0;
-    //    if([[UIScreen mainScreen]respondsToSelector:@selector(scale)]) {
-    //        CGFloat tmp = [[UIScreen mainScreen]scale];
-    //        if (tmp > 1.5) {
-    //            scale = 2.0;
-    //        }
-    //    }
-    sz.width /= scale;
-    sz.height /= scale;
-    UIGraphicsBeginImageContextWithOptions(sz, NO, scale);
-    [image drawInRect:CGRectMake(0, 0, sz.width, sz.height)];
-    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
-    UIGraphicsEndImageContext();
-    return newImage;
 }
+*/
+
 @end

+ 1 - 0
iOSClient/Utility/CCGraphics.h

@@ -38,5 +38,6 @@
 + (void)saveIcoWithFileID:(NSString *)fileID image:(UIImage *)image writeToFile:(NSString *)writeToFile copy:(BOOL)copy move:(BOOL)move fromPath:(NSString *)fromPath toPath:(NSString *)toPath;
 
 + (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)targetSize;
++ (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)targetSize isAspectRation:(BOOL)aspect;
 
 @end

+ 31 - 0
iOSClient/Utility/CCGraphics.m

@@ -114,6 +114,37 @@
     return scaledImage;
 }
 
++ (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)targetSize isAspectRation:(BOOL)aspect
+{
+    CGFloat originRatio = image.size.width / image.size.height;
+    CGFloat newRatio = targetSize.width / targetSize.height;
+    CGSize sz;
+    CGFloat scale = 1.0;
+    
+    if (!aspect) {
+        sz = targetSize;
+    }else {
+        if (originRatio < newRatio) {
+            sz.height = targetSize.height;
+            sz.width = targetSize.height * originRatio;
+        }else {
+            sz.width = targetSize.width;
+            sz.height = targetSize.width / originRatio;
+        }
+    }
+    
+    sz.width /= scale;
+    sz.height /= scale;
+    
+    UIGraphicsBeginImageContextWithOptions(sz, NO, scale);
+    [image drawInRect:CGRectMake(0, 0, sz.width, sz.height)];
+    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
+    UIGraphicsEndImageContext();
+    
+    return newImage;
+}
+
+
 + (UIImage *)createNewImageFrom:(NSString *)fileName directoryUser:(NSString *)directoryUser fileNameTo:(NSString *)fileNameTo fileNamePrint:(NSString *)fileNamePrint size:(NSString *)size imageForUpload:(BOOL)imageForUpload typeFile:(NSString *)typeFile writePreview:(BOOL)writePreview optimizedFileName:(BOOL)optimizedFileName
 {
     UIImage *originalImage;