Skip to content

Commit 1d494b5

Browse files
committed
Add a customAppearance property to action sheet item
1 parent 9e613e2 commit 1d494b5

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,19 @@ with no transparent background.
173173
## Appearance
174174

175175
Sheets can be globally styled by using the `ActionSheetAppearance.standard`. All
176-
sheets copy this appearance when they are created. They can then be individually
177-
styled without affecting the global appearance.
176+
action sheet items will then copy this appearance upon creation, and apply it to
177+
all items each time it refreshes its content.
178+
179+
If you want to apply a global style for all your action sheets, simply style the
180+
`ActionSheetAppearance.standard` property and all action sheets will be affected.
181+
182+
If you want to apply an individual style to a single action sheet, just style it
183+
using its `appearance` property (a copy of `ActionSheetAppearance.standard`), or
184+
completely replace it with a completely different appearance instance.
185+
186+
If you want to apply an individual style to a single action sheet item, just set
187+
its optional `customAppearance` property to any custom value. Just be careful to
188+
copy any other appearance, otherwise you'll affect the original style.
178189

179190
Have a look at the example app to see how global and individual appearances work.
180191

RELEASENOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Sheeeeeeeeet may have breaking changes in minor versions and revisions below 1.0
55

66
## 0.11.0
77

8-
This minor version fixes some appearance glitches and makes the appearance setup
9-
more consistent.
8+
This version adds a `customAppearance` property to `ActionSheetItem` and fixes a
9+
few appearance glitches. Overall, it makes the appearance setup more consistent.
1010

1111
* I use early returns in every appearance class and have optimized imports. Many
1212
appearance classes have also been made `open` instead of `public`.

Sheeeeeeeeet/Items/ActionSheetItem.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ open class ActionSheetItem: NSObject {
7272

7373
open var appearance: ActionSheetItemAppearance
7474
open var cellStyle: UITableViewCell.CellStyle = .default
75+
open var customAppearance: ActionSheetItemAppearance?
7576
open var tapBehavior: TapBehavior
7677

7778

7879
// MARK: - Functions
7980

8081
open func applyAppearance(_ appearance: ActionSheetAppearance) {
81-
self.appearance = ActionSheetItemAppearance(copy: appearance.item)
82+
self.appearance = customAppearance ?? ActionSheetItemAppearance(copy: appearance.item)
8283
}
8384

8485
open func applyAppearance(to cell: UITableViewCell) {

SheeeeeeeeetExample/ActionSheets/HeaderActionSheet.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ private extension HeaderActionSheet {
3030

3131
static func items(for options: [FoodOption]) -> [ActionSheetItem] {
3232
var items = options.map { $0.item() }
33+
34+
items[0].customAppearance = ActionSheetItemAppearance(copy: ActionSheetAppearance.standard.item)
35+
items[0].customAppearance?.textColor = .red
36+
items[0].customAppearance?.separatorInsets.left = 100
37+
3338
items.insert(titleItem(title: standardTitle), at: 0)
3439
items.append(cancelButton)
3540
return items

0 commit comments

Comments
 (0)