Eureka: Resize the segmented control

Created on 4 Jun 2016  路  2Comments  路  Source: xmartlabs/Eureka

Is there a way to set a custom width for SegmentedRows? If not, is it possible to add the ability in a future release?

SegmentedRow enhancement

Most helpful comment

I did this with an extension for now:

extension SegmentedCell {
    func setControlWidth(_ width: CGFloat) {
        guard let segmentedControl = segmentedControl else { return }
        let constraint = NSLayoutConstraint(
            item: segmentedControl,
            attribute: .width,
            relatedBy: .equal,
            toItem: nil,
            attribute: .notAnAttribute,
            multiplier: 1,
            constant: width
        )
        addConstraint(constraint)
    }
}

SegmentedRow<String> {
    $0.title = "Choose"
    $0.options = ["A", "B", "C"]
}.cellUpdate { cell, _ in
    cell.setControlWidth(300)
}

All 2 comments

I did this with an extension for now:

extension SegmentedCell {
    func setControlWidth(_ width: CGFloat) {
        guard let segmentedControl = segmentedControl else { return }
        let constraint = NSLayoutConstraint(
            item: segmentedControl,
            attribute: .width,
            relatedBy: .equal,
            toItem: nil,
            attribute: .notAnAttribute,
            multiplier: 1,
            constant: width
        )
        addConstraint(constraint)
    }
}

SegmentedRow<String> {
    $0.title = "Choose"
    $0.options = ["A", "B", "C"]
}.cellUpdate { cell, _ in
    cell.setControlWidth(300)
}

@samrayner It's a good solution.
Alternatively you can extend SegmentedRow and its cell and update its constraints. Anyway your solution seems more elegant and easier.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zoul picture zoul  路  3Comments

Tomas1405 picture Tomas1405  路  3Comments

JonathanImperato picture JonathanImperato  路  3Comments

tc picture tc  路  3Comments

thlbaut picture thlbaut  路  3Comments