How to set a UILabel as a percentage of the width of the UICell with autolayout

I’m wondering how to set a UILabel’s width expressed as a % of the Cell’s total width? I’m using AutoLayout. Normally I would click on the label and set the EqualsWidth to a parentView and then adjust the multiplier so I set the width as a % of the parentWidth. But using InterfaceBuilder that option does not seem to be available within the Cell. enter image description here

However I’m wondering maybe it has something to do with setting the preferred Width: I’m using ios8+ and have read that implicit widths are not available for ios8?

  • iOS Image Orientation has Strange Behavior
  • How to initialise a UIView Class with a xib file in Swift, iOS
  • UIScrollView wrong offset with Auto Layout
  • Xcode attempted to locate or generate matching signing assets and failed to do so
  • XEP - 0055 with iOS and ejabberd?
  • iPhone Simulator location
  • enter image description here

    What I am hoping to achieve is that Label 1 and Label 3 are both 15% the width of the Cell and Label 2 has leading and trailing edges pinned to UIImageView and Label 3 that will allow it to grow and shrink depending on the width of the device.
    enter image description here

    2 Solutions Collect From Internet About “How to set a UILabel as a percentage of the width of the UICell with autolayout”

    Steps you should do to achieve your goal of setting percentage width of any subview inside cell:

    1. Add UIView to your cell and pin it to every edge – we have to add custom container view in order to be able to add “Widths equally” pin later on.

    2. Add UILabel to previously added UIView container. Lets say we want to add left side label, so add 3 pins to it: left, top, bottom.

    3. You can see now that you have error in your constraint setup. So lets fix it and add “Widths equally” pin. Select 2 views in View Controller Scene menu – the container and the label. Go to XcodeMenu/Editor/Pin/ and select “Widths equally”. Now you should see no errors in you constraints setup and the label should have same size as the container. (Please note that sometimes you have to refresh frames of your views after setting constraints, so if you see “yellow” warning icon don’t be afraid and just click on it).

    4. Now if you have all your constraints we need to set actual percentage value. Open tab Size Inspector, click “Edit” title on constraint added in step 3. and change Multiplier value to 0.15 (15%).

    Please note that, if you would add label using same technique but for right side, then you would need to set Multiplier value to 6.66 (= 1.00 / 0.15).

    Cheers!

    enter image description here

    You can set width constraint and then create an IBOutlet for that in UITableView cell and change constraint.constant value in layoutSubView method of tableViewCell