Skip to content

Commit

Permalink
Added tinting for images.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Dec 21, 2021
1 parent 0285e20 commit 06d3152
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PresetsController: SPDiffableTableController {
name: "Custom Image",
title: "Custom Image",
message: "Passed UIImage object for preset with style custom.",
preset: .custom(UIImage.init(systemName: "pencil.and.outline")!.withRenderingMode(.alwaysOriginal))
preset: .custom(UIImage.init(systemName: "pencil.and.outline")!.withRenderingMode(.alwaysTemplate))
),
]
}
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ I tried to recreate Apple's alerts as much as possible. You can find these alert
- [Layout](#layout)
- [Haptic](#haptic)
- [Spinner](#spinner)
- [Appearance](#appearance)
- [Colors](#colors)
- [Global Appearance](#global-appearance)
- [SwiftUI](#swiftui)
- [Russian Community](#russian-community)

Expand All @@ -38,7 +39,7 @@ Once you have your Swift package set up, adding as a dependency is as easy as ad

```swift
dependencies: [
.package(url: "https://github.com/ivanvorobei/SPAlert", .upToNextMajor(from: "4.0.0"))
.package(url: "https://github.com/ivanvorobei/SPAlert", .upToNextMajor(from: "4.0.1"))
]
```

Expand Down Expand Up @@ -147,7 +148,18 @@ alertView.dismiss()
SPAlert.dismiss()
```

### Appearance
### Colors

For change color of icon, simple set tint color for any preset:

```swift
alertView.iconView?.tintColor = .systemRed

//If you set custom image, don't forget set rendering mode:
UIImage(systemName: "pencil.and.outline")!.withRenderingMode(.alwaysTemplate)
```

### Global Appearance

Also you can change some default values for alerts. For example you can change default duration and corner radius for alert with next code:

Expand Down
2 changes: 1 addition & 1 deletion SPAlert.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'SPAlert'
s.version = '4.0.0'
s.version = '4.0.1'
s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.'
s.homepage = 'https://github.com/ivanvorobei/SPAlert'
s.source = { :git => 'https://github.com/ivanvorobei/SPAlert.git', :tag => s.version }
Expand Down
8 changes: 3 additions & 5 deletions Sources/SPAlert/SPAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ open class SPAlertView: UIView {
style.lineSpacing = 3
style.alignment = .center
label.attributedText = NSAttributedString(string: text, attributes: [.paragraphStyle: style])
label.textColor = defaultContentColor
titleLabel = label
addSubview(label)
}
Expand All @@ -157,12 +158,14 @@ open class SPAlertView: UIView {
style.lineSpacing = 2
style.alignment = .center
label.attributedText = NSAttributedString(string: text, attributes: [.paragraphStyle: style])
label.textColor = defaultContentColor
subtitleLabel = label
addSubview(label)
}

private func setIcon(for preset: SPAlertIconPreset) {
let view = preset.createView()
view.tintColor = defaultContentColor
self.iconView = view
addSubview(view)
}
Expand Down Expand Up @@ -208,11 +211,6 @@ open class SPAlertView: UIView {

self.completion = completion

let contentСolor = defaultContentColor
titleLabel?.textColor = contentСolor
subtitleLabel?.textColor = contentСolor
iconView?.tintColor = contentСolor

alpha = 0
setFrame()
transform = transform.scaledBy(x: self.presentDismissScale, y: self.presentDismissScale)
Expand Down

0 comments on commit 06d3152

Please sign in to comment.