Browse Source

coding Avatar

marinofaggiana 4 years ago
parent
commit
bdd48abe6a

+ 1 - 1
iOSClient/Extensions/UIImageView+Extensions.swift

@@ -26,7 +26,7 @@ import Foundation
 
 
 extension UIImageView {
 extension UIImageView {
     
     
-    func avatar(roundness: CGFloat = 2, borderWidth: CGFloat = 1, borderColor: UIColor = .lightGray, backgroundColor: UIColor = .clear) {
+    @objc func avatar(roundness: CGFloat = 2, borderWidth: CGFloat = 1, borderColor: UIColor = .lightGray, backgroundColor: UIColor = .clear) {
         
         
         layer.cornerRadius = bounds.width / roundness
         layer.cornerRadius = bounds.width / roundness
         layer.borderWidth = borderWidth
         layer.borderWidth = borderWidth

+ 3 - 2
iOSClient/Settings/CCManageAccount.m

@@ -61,8 +61,9 @@
         if (avatar) {
         if (avatar) {
             
             
             avatar = [avatar resizeImageWithSize:CGSizeMake(35, 35) isAspectRation:false];
             avatar = [avatar resizeImageWithSize:CGSizeMake(35, 35) isAspectRation:false];
-            NCAvatar *avatarImageView = [[NCAvatar alloc] initWithImage:avatar borderColor:[UIColor whiteColor] borderWidth:1];
-                        
+            UIImageView *avatarImageView = [[UIImageView alloc] initWithImage:avatar];
+            [avatarImageView avatarWithRoundness:2 borderWidth:1 borderColor:[UIColor lightGrayColor] backgroundColor:[UIColor clearColor]];
+            
             CGSize imageSize = avatarImageView.bounds.size;
             CGSize imageSize = avatarImageView.bounds.size;
             UIGraphicsBeginImageContextWithOptions(imageSize, NO, UIScreen.mainScreen.scale);
             UIGraphicsBeginImageContextWithOptions(imageSize, NO, UIScreen.mainScreen.scale);
             CGContextRef context = UIGraphicsGetCurrentContext();
             CGContextRef context = UIGraphicsGetCurrentContext();

+ 2 - 19
iOSClient/Utility/NCAvatar.swift

@@ -32,7 +32,7 @@ import Foundation
         }
         }
     }
     }
     
     
-    @IBInspectable var borderWidth: CGFloat = 5 {
+    @IBInspectable var borderWidth: CGFloat = 1 {
         didSet{
         didSet{
             layoutSubviews()
             layoutSubviews()
         }
         }
@@ -58,26 +58,9 @@ import Foundation
         super.init(frame: frame)
         super.init(frame: frame)
     }
     }
     
     
-    @objc init(image: UIImage?, borderColor: UIColor, borderWidth: CGFloat) {
-        super.init(image: image)
-        
-        self.borderColor = borderColor
-        self.borderWidth = borderWidth        
-    }
-
     override func layoutSubviews() {
     override func layoutSubviews() {
         super.layoutSubviews()
         super.layoutSubviews()
                 
                 
-        layer.cornerRadius = bounds.width / roundness
-        layer.borderWidth = borderWidth
-        layer.borderColor = borderColor.cgColor
-        layer.backgroundColor = background.cgColor
-        clipsToBounds = true
-        
-        let path = UIBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), cornerRadius: bounds.width / roundness)
-        let mask = CAShapeLayer()
-        
-        mask.path = path.cgPath
-        layer.mask = mask
+        self.avatar(roundness: roundness, borderWidth: borderWidth, borderColor: borderColor, backgroundColor: background)
     }
     }
 }
 }