Swift:Main.Storyboard本地化失败

Swift:Main.Storyboard本地化失败

问题描述:

我正在使用Xcode 7.3.1并尝试为我的项目设置本地化版本我试图局部Main.storyboard文件Swift:Main.Storyboard本地化失败

Screenshot 1

Screenshot 2

第二屏幕截图显示Main.storyboard被局部化。但是,这并不反映在Main.Storyboard(截图1)中。它应该像截图3

Screenshot 3

注:Main.Storyboard文件包含约10场景。

什么解决?

+0

你在正确的方法 –

+0

@ Anbu.Karthik:然后在哪里写t控制的转换值,即“uJE-ia-usa.text”=“印地文文本”; –

+0

我添加了答案检查一次bro –

第1步

选择stroyboard - >去文件检查器 - >本地化 - >启用刻度线为你的语言

你得到的输出喜欢

enter image description here

步骤2

finaly你得到的输出喜欢

enter image description here

+0

步骤2未显示在我的案例中。为什么这样? –

+0

您可以发送该项目我会做这 –

+0

@ Anbu.kartik:机密项目..不能共享它 –

你应该写ClassesXIB OR StoryboardViews &使用您的controls分配Classes到相应的控制类型,像这样 -

class LocalizedTextField: UITextField { 

    override func drawPlaceholderInRect(rect: CGRect) { 

     let localizedPlaceHolder = self.placeholder!.localized 
     self.placeholder = localizedPlaceHolder 
     super.drawPlaceholderInRect(rect) 
    } 
} 
class LocalizedLabel : UILabel { 
    override func awakeFromNib() { 
     if let text = text { 
      self.text = text.localized 
      self.bounds.size.width = CGFloat.max 
      self.sizeToFit() 
     } 
    } 
} 

class LocalizedButton : UIButton { 
    override func awakeFromNib() { 
     for state in [UIControlState.Normal, UIControlState.Highlighted, UIControlState.Selected, UIControlState.Disabled, UIControlState.Focused] { 
      if let title = titleForState(state) { 
       setTitle(title.localized, forState: state) 
      } 
     } 
    } 
} 

extension String { 

    var localized: String { 
     let localizedValue = NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: "") 
     if localizedValue == "" { 

      return self 
     } 
     else 
     { 
      return localizedValue 
     } 
     return self 

    } 
} 

enter image description here