lundi 20 avril 2015

Swift repeatable styles

I'm just wondering what a good pattern is for having repeatable styles for UI elements, for example UITableView. Right now I just use extensions and call a method to style the current instance. Like so:

extension UITableView
{

    /**
     * Sets default table style
     */
    func setDefaultStyle()
    {
        self.backgroundColor = Helper.customColor(Settings.color["grey"]!)
        self.separatorColor = Helper.customColor(Settings.color["greyDark"]!)
        self.removePadding()
        self.removeFooter()
        self.addBorderTop()
    }

    /**
     * Insert top border above table frame
     */
    func addBorderTop()
    {
       ...
    }


}

But I just can't imagine this is a great way to do things, because I could eventually have a bunch of different styles and a ton of extra methods for styling them cluttering up the UITableView definition. I've been told subclassing is generally not the way to go either, but maybe that wasn't correct advice. Just wondering what some opinions were on this topic?

Aucun commentaire:

Enregistrer un commentaire