Browse Source

Merge pull request #771 from deltachat/hourglass

implement adaptive tint color for hourglass icon
bjoern 5 years ago
parent
commit
078c3eee3d

+ 1 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -922,7 +922,7 @@ extension ChatViewController: MessagesDataSource {
 
         switch Int32(state) {
         case DC_STATE_OUT_PENDING, DC_STATE_OUT_PREPARING:
-            imageAttachment.image = #imageLiteral(resourceName: "ic_hourglass_empty_36pt").scaleDownImage(toMax: 16)
+            imageAttachment.image = #imageLiteral(resourceName: "ic_hourglass_empty_white_36pt").scaleDownImage(toMax: 16)?.maskWithColor(color: DcColors.grayDateColor)
             imageAttachment.image?.accessibilityIdentifier = String.localized("a11y_delivery_status_sending")
             offset = -2
         case DC_STATE_OUT_DELIVERED:

+ 24 - 0
deltachat-ios/Extensions/UIImage+Extension.swift

@@ -12,6 +12,30 @@ extension UIImage {
         return self
     }
 
+     func maskWithColor(color: UIColor) -> UIImage? {
+         let maskImage = cgImage!
+
+         let width = size.width
+         let height = size.height
+         let bounds = CGRect(x: 0, y: 0, width: width, height: height)
+
+         let colorSpace = CGColorSpaceCreateDeviceRGB()
+         let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
+         let context = CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)!
+
+         context.clip(to: bounds, mask: maskImage)
+         context.setFillColor(color.cgColor)
+         context.fill(bounds)
+
+         if let cgImage = context.makeImage() {
+             let coloredImage = UIImage(cgImage: cgImage)
+             return coloredImage
+         } else {
+             return nil
+         }
+     }
+
+
     public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
         let rect = CGRect(origin: .zero, size: size)
         UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)

+ 1 - 1
deltachat-ios/View/ContactCell.swift

@@ -196,7 +196,7 @@ class ContactCell: UITableViewCell {
         } else {
             switch Int32(status) {
             case DC_STATE_OUT_PENDING, DC_STATE_OUT_PREPARING:
-                deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_hourglass_empty_36pt")
+                deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_hourglass_empty_white_36pt").maskWithColor(color: DcColors.middleGray)
             case DC_STATE_OUT_DELIVERED:
                 deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_done_36pt")
             case DC_STATE_OUT_FAILED: