How to use style class?
Closed this issue · 5 comments
cresouls commented
How can I use style class to align titleLabel to left?
neoneye commented
I'm sorry Sreejith, there is currently no way to control alignment.
I don't understand you. How would you like it to work?
cresouls commented
For ButtonFormItem, the title is aligned to centre. For some cases, I need to align it left.
neoneye commented
You can use the CustomFormItem
class for a left-aligned UILabel
or UIButton
.
In the Example project, take a look at the CustomViewController
loading the LoadingCell
.
Good luck Sreejith
Thank you for feedback on ButtonFormItem
.
cresouls commented
Ok. I will try. Thanks for your prompt reply. :)
cresouls commented
Thanks Simon. It worked!
In case if it helps someone:
- Create CustomButtonCell.swift
import SwiftyFORM
class CustomButtonCell: UITableViewCell, SelectRowDelegate {
var action: (()->())!
public init(_ title: String) {
super.init(style: .default, reuseIdentifier: nil)
loadWithModel(title: title)
}
public required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func loadWithModel(title: String) {
textLabel?.text = title
textLabel?.textAlignment = NSTextAlignment.left
}
public func form_didSelectRow(indexPath: IndexPath, tableView: UITableView) {
// hide keyboard when the user taps this kind of row
tableView.form_firstResponder()?.resignFirstResponder()
action()
tableView.deselectRow(at: indexPath, animated: true)
}
}
- In populate function of your viewController add this:
let customButton = CustomFormItem()
customButton.createCell = { _ in
let customButtonCell: CustomButtonCell = CustomButtonCell("Contact us")
customButtonCell.action = {
//Your custom action
}
return customButtonCell
}
builder += customButton