Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add extended support for SF Symbol configuration #489

Open
funnel20 opened this issue Feb 16, 2024 · 6 comments
Open

Please add extended support for SF Symbol configuration #489

funnel20 opened this issue Feb 16, 2024 · 6 comments

Comments

@funnel20
Copy link
Contributor

I'm very pleased that InAppSettingsKit version 3.6 now supports SF Symbols via systemImageNamed:.

One question though, as this opens the door to more customisation. In our apps we use even more native power with systemImageNamed:withConfiguration:.
For example to apply palette colouring on a SF Symbol:
Screenshot 2024-02-16 at 10 23 29

// Define image name and configuration:
NSString *name = @"cloud.sun";
UIImageConfiguration *config = [UIImageSymbolConfiguration configurationWithPaletteColors:@[
    [UIColor systemTealColor],      // cloud
    [UIColor systemYellowColor]     // sun
]];

// Create image:
UIImage *image = [UIImage systemImageNamed:name
                         withConfiguration:config];

Since you already use IASKCellImage as name, would it be possible to extend InAppSettingsKit with something like a IASKCellImageConfiguration, which refers to the name of Class variable of the parent ViewController (e.g. config in this example)?

The good part of systemImageNamed:withConfiguration: is that even if config is nil, it will ignore the configuration and just acts as systemImageNamed:.

Thank you for considering this improvement.

@futuretap
Copy link
Owner

This is certainly a good idea. I suggest adding a symbolImageConfiguration property to IASKAppSettingsViewController. That property would have to be copied to all child view controllers (similar to how the delegate is assigned to child VCs). Is probably easier to use, especially from Swift code.

Would you be so kind to contribute a pull request? ;-)

@funnel20
Copy link
Contributor Author

@futuretap I was hoping to apply multiple different Symbol Configurations per ViewController, as the layout might request one configuration per image.
Consider for example the native iOS Settings app, it consists of a wide range of coloured icons:

IMG_8B84F6225CA7-1

Hence my idea of a new parameter in the .plist

@futuretap
Copy link
Owner

I see. To achieve this example, you’d need a separate class for each background color. Doesn't really scale well, too.
If I were you, I'd implement the -settingsViewController:cellForSpecifier: delegate callback and set

cell.imageView.image = cell.imageView.image.withConfiguration(yourConfiguration)

Then you can switch on specifier.key to create a configuration per key. Does that work for you?

@funnel20
Copy link
Contributor Author

@futuretap That's a great idea, thank you very much.

@funnel20
Copy link
Contributor Author

funnel20 commented Oct 3, 2024

I see. To achieve this example, you’d need a separate class for each background color. Doesn't really scale well, too. If I were you, I'd implement the -settingsViewController:cellForSpecifier: delegate callback and set

cell.imageView.image = cell.imageView.image.withConfiguration(yourConfiguration)

Then you can switch on specifier.key to create a configuration per key. Does that work for you?

@futuretap I have tried this via:

- (UITableViewCell*)settingsViewController:(UITableViewController<IASKViewController>*)settingsViewController
                          cellForSpecifier:(IASKSpecifier*)specifier {
    NSLog(@"settingsViewController:cellForSpecifier:");
    
    NSIndexPath* indexPath = [settingsViewController.settingsReader indexPathForKey:specifier.key];
    UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
    
    if ([specifier.key isEqualToString:@"TEST"]) {
        NSString *name = @"cloud.sun";
        UIImageConfiguration *config = [UIImageSymbolConfiguration configurationWithPaletteColors:@[
            [UIColor systemTealColor],      // cloud
            [UIColor systemYellowColor]     // sun
        ]];

        // Create image:
        UIImage *image = [UIImage systemImageNamed:name
                                 withConfiguration:config];
        
        cell.imageView.image = image;
    }
    
    return cell;
}

But the delegate method is never called (I don't see the NSLog()). It will be only called for a Custom View.
But I'd like to apply the SF Configuration on a standard cell, for example a PSChildPaneSpecifier.

Would it be an idea to add a new delegate to customize the image based on identifier? E.g. like:

- (UIImage*)settingsViewController:(UITableViewController<IASKViewController>*)settingsViewController
                 imageForSpecifier:(IASKSpecifier*)specifier;

@futuretap
Copy link
Owner

Indeed, the delegate is only called for IASKCustomViewSpecifier cells (as documented).
Alternatively, you can subclass IASKAppSettingsViewController and override -tableView:cellForRowAtIndexPath:.

There are so many different properties of a cell that imo it doesn’t scale to add delegate callbacks for all of these. We might rather think of a customizeCell callback that allows the delegate to manipulate any cell after IASK has done its work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants