Swift 3如何以编程方式修改乘数约束

时间:2017-04-09 03:07:59

标签: ios swift

我有一个字段标签的乘数约束设置和表格单元格中的字段值。请参见附件截图。我想根据字段标签有条件地修改约束。因此,字段值将根据需要具有更多宽度。任何建议将不胜感激。

我正在使用switch语句来设置字段标签和值。见下文。

switch indexPath.row {
        case 0:
            cell.fieldLabel.text = "Program: "
            cell.valueLabel.text = services.name
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Heavy", size: 20.0)
            cell.valueLabel.textColor = UIColor(red: 164.0/255.0, green: 45.0/255.0, blue: 9.0/255.0, alpha: 1.0)
        case 1:
            cell.fieldLabel.text = "Branch: "
            cell.valueLabel.text = services.branch
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Light", size: 16.0)
            cell.valueLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
        case 2:
            cell.fieldLabel.text = "Phone: "
            cell.valueLabel.text = services.mainPhone
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Light", size: 16.0)
            cell.valueLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
        case 3:
            cell.fieldLabel.text = "Locations: "
            cell.valueLabel.text = services.locations
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Light", size: 16.0)
            cell.valueLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.accessoryType = .disclosureIndicator


        case 4:
            cell.fieldLabel.text = "Hours: "
            cell.valueLabel.text = services.hours
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Light", size: 16.0)
            cell.valueLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)

        case 5:
            cell.fieldLabel.text = "Website: "
            cell.valueLabel.text = services.website
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Light", size: 16.0)
            cell.valueLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)

        case 6:
            cell.fieldLabel.text = " "
            cell.valueLabel.text = services.longDesc
            cell.fieldLabel.font = UIFont(name: "Avenir-Medium", size: 14.0)
            cell.fieldLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
            cell.valueLabel.font = UIFont(name: "Avenir-Light", size: 16.0)
            cell.valueLabel.textColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)

        default:
            cell.fieldLabel.text = ""
            cell.valueLabel.text = ""
        }

Screenshot of Interface Builder Constraint and Layout

0 个答案:

没有答案