Hi, thanks for such a great library!
I have a small question, is it possible to customize (for example set a text color) for all the rows that are inherited from FieldRow (NameRow, EmailRow, PasswordRow etc.) at once? and the same about different types of PushRow, thanks a lot!
I am having a similar issue. I want to set the font for all the labels to the main font for my app which I'm doing like this:
TextRow.defaultCellUpdate = { cell, row in
cell.textField.font = UIFont.appFont()
}
PasswordRow.defaultCellUpdate = { cell, row in
cell.textField.font = UIFont.appFont()
}
EmailRow.defaultCellUpdate = { cell, row in
cell.textField.font = UIFont.appFont()
}
PhoneRow.defaultCellUpdate = { cell, row in
cell.textField.font = UIFont.appFont()
}
ZipCodeRow.defaultCellUpdate = { cell, row in
cell.textField.font = UIFont.appFont()
}
SwitchRow.defaultCellUpdate = { cell, row in
cell.textLabel?.font = UIFont.appFont()
}
and I need to add a new one for each Row I add to the app. It seems like a tremendous amount of repetition. Since a lot of these cells have a textField could this be pulled out into a generically accessible protocol and an extension to manipulate some of the common elements of these cells? Maybe something like that already is possible and I just haven't figured it out yet?
I am having a similar issue.And I'm doing like this:
func defaultTextFieldCellUpdate<T0: TextFieldCell, T1:FieldRowConformance>(cell: T0, row: T1) -> () {
let title = (row as! BaseRow).title
if (title != nil ) && (row.placeholder == nil){
let placeholder = "请输入".stringByAppendingString(title!)
cell.textField.placeholder = placeholder
}
if let label:UILabel = cell.textField.valueForKeyPath("_placeholderLabel") as? UILabel {
guard label.isKindOfClass(UILabel) else {
return
}
label.font = UIFont.systemFontOfSize(13)
label.minimumScaleFactor = 0.8
label.adjustsFontSizeToFitWidth = true
label.baselineAdjustment = .None
}
}
IntRow.defaultCellUpdate = { cell, row in
defaultTextFieldCellUpdate(cell, row:row)
}
TextRow.defaultCellUpdate = { cell, row in
defaultTextFieldCellUpdate(cell, row:row)
}
PhoneRow.defaultCellUpdate = { cell, row in
defaultTextFieldCellUpdate(cell, row:row)
}
DecimalRow.defaultCellUpdate = { cell, row in
defaultTextFieldCellUpdate(cell, row:row)
}
I agree that it is not great to have to do this for every FieldRow. Currently there is no better way. We might enhance this...
This can easily be encapsulated within a function. I suggest to share a gist with the solution so anyone can use it. Anyone want to help by coding the gist?
This is the easy way to set up the same font to every Field row.
updateFont(row: TextRow.self)
updateFont(row: PasswordRow.self)
updateFont(row: EmailRow.self)
updateFont(row: DecimalRow.self)
// ..
func updateFont<Row>(row: Row.Type) where Row: RowType, Row: BaseRow, Row: FieldRowConformance{
Row.defaultCellUpdate = { cell, row in
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 12)
}
}
Am very new to swift and so struggle a lot with customising my own rows and cells. Could you advise on how can I adapt the above updateFont to allow me to also update the cell.textField from the FieldRows? Right now, I have the below for every type of rows I use (9 and increasing!)
DecimalRow.defaultCellUpdate = { cell, row in
cell.textLabel?.font = self.phFontBold
cell.textField.font = self.phFont
cell.textField.textColor = self.getTextColor()
cell.backgroundColor = self.getBackgroundColor()
}
DateTimeInlineRow.defaultCellUpdate = { cell, row in
cell.textLabel?.font = self.phFontBold
cell.detailTextLabel?.font = self.phFont
cell.detailTextLabel?.textColor = self.getTextColor()
cell.backgroundColor = self.getBackgroundColor()
}
Most helpful comment
I agree that it is not great to have to do this for every FieldRow. Currently there is no better way. We might enhance this...