NSLocalization + Storyboard using Swift

Lucas

So this is very strange:

I created a small UIView in Storyboard, changed its color so we can see it. I also created a button so I can make this view bigger.

What happens is it only works if I don't access NSLocalizedString. If I decomment the line it stops working.

Why is this?

class MasterViewController: UIViewController {

    @IBOutlet weak var bar: UIView!
    @IBOutlet weak var button: UIButton!

    var integer : Int = 0

    @IBAction func makeBarGrow(sender : AnyObject) {
        self.integer++
       //self.button.setTitle(NSLocalizedString("test \(integer)", comment : "test"), forState:UIControlState.Normal)
        self.bar.frame = CGRectMake(self.bar.frame.origin.x,
            self.bar.frame.origin.y,
            self.bar.frame.size.width + 10,
            self.bar.frame.size.height)
    }
}

Thank you

vacawama

When you set the label on your button, Auto Layout runs and sets the frame of your bar back to its initial value. When Auto Layout is enabled, you shouldn't adjust frame sizes. Instead, you should use size constraints like so:

  1. Add an Auto Layout constraint on your bar that sets its width. To do this, select your bar view in Interface Builder and click the Auto Layout Pin icon |-[]-|, click the box next to Width, and set the constant to your desired initial value. Then click Add 1 Constraint at the bottom.

  2. Add an IBOutlet to this constraint in your ViewController by Control dragging from the constraint in the Document Layout View to your code:

    @IBOutlet weak var barWidth: NSLayoutConstraint!
    
  3. In makeBarGrow, replace frame adjusting code with:

    barWidth.constant += 10
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass data back with no storyboard using Swift

how to add element using swift to a storyboard stackview

Custom UITableViewCell created using Storyboard shows no label data - Swift

Swift storyboard - Creating a segue in MapView using calloutaccessorycontroltapped disclosure button

OSX application without storyboard or xib files using Swift

Passing Data through View Controllers with Swift without Using Storyboard

Swift go to a view by clicking on a button without using StoryBoard

Autolayout and storyboard not working - Swift?

Add storyboard in Swift

Swift Eureka Storyboard

storyboard localization in swift 4.0

Swift Storyboard "Illegal Configuration"

im trying to add a header section to my profile page using swift (Xcode) with out using the storyboard

NSWindowController Autosave using Storyboard

Using a Storyboard on a ToolTip WPF

Conditional Segue Using Storyboard

UITabBar width using Storyboard

Using Storyboard ViewControllers

Using UITableView without a storyboard

Swift: How to show child view controllers via storyboard rather than programmatically using XLPagerTabStrip

How can i use the IBAction botton to go to the next storyboard using Swift?

How to set initial controller programmatically from storyboard in Cocoa using Swift 4 Xcode 10?

How to properly create a storyboard in xCode6 using Interface Builder and Swift

Swift set UIButton setBorderColor in Storyboard

Swift: How to implement a login storyboard?

Swift instantiateViewController without storyboard ?programming

iOS Swift: SearchController with a StoryBoard UISearchBar

IBOutlet is nil, but it is connected in storyboard, Swift

present viewController in another storyboard swift