Nur II
Nur II

Reputation: 171

Re-position uilabel

I wanted the "number" & "status" to display on the left if there is not QRCode display (constraints has been set for image & labels.)

Result without QRCode:
enter image description here.

The result with QRCode will be:
enter image description here

Upvotes: 0

Views: 120

Answers (4)

Joyal Clifford
Joyal Clifford

Reputation: 1212

This Problem is very simple , can achieve using UIStackView just making hide/Show.

For Ex: If QR-code is present show or else hide QR-Code. Label (Number and status and image) will automatically get adjust. Following is the screen short for better understanding.

enter image description here

IBOutlet UIView *qr_view; // Image or View

Case 1 :QR Present

qr_view.hidden = NO;// Show

enter image description here

Case 2: QR Not Present

 qr_view.hidden = YES;// hide

enter image description here

Upvotes: 0

Eridana
Eridana

Reputation: 2408

You could make constraint for labels that way:

I.e. make constraint for image leading to left side + image width, both labels also have leading to left side. Then if there is no QR Code adjust labels leading constraints to value you need.

Or you could make both labels leading to image view and set the image view width constraint to 0.

pic

Upvotes: 1

Jaydeep Vyas
Jaydeep Vyas

Reputation: 4470

IT IS very easy just make width Constraint of QRcode image, if QR code is not available than make widht constant = 0,

enter image description here

  @IBOutlet weak var width: NSLayoutConstraint!
    if (your condition)
    {
       width.constant = 0
    }
    else
    {
       width.constant = 30
    }

Upvotes: 3

DoN1cK
DoN1cK

Reputation: 615

You can do that with a second pair of constraints attached to left side of a view.

Add outlets to that constraints and set constant value to desired offset(from code), if there is no QRCode View.

Another way is to add MoreThanOrEquel constraint to left side (e.g >= 10) Than another constraint with constant value 10, but with lower priority.

When you remove QRCode view, it will destroy it constraints and constraints to left side will affects and move yours labels to left.

Upvotes: 2

Related Questions