简体   繁体   English

iOS-用于本地化故事板Scene / ViewController的最佳架构

[英]iOS - best architecture for localizing a storyboard Scene/ViewController

I have inherited an existing storyboard which has a viewController called loginScreen. 我继承了一个现有的情节提要,其中有一个名为loginScreen的viewController。 It looks like something similar to this: 看起来类似于以下内容:

在此处输入图片说明

and this exists in the main.storyboard 这存在于main.storyboard中

We have created another target for a new product we are launching. 我们为正在发布的新产品创建了另一个目标。 This product is extremely similiar to the inital one i inherited so the target is a copy of the original. 该产品非常类似于我继承的初始产品,因此目标是原始产品的副本。 To get to the point of the question on the login screen i showed a image of the UX team would like certain things changed here is an puesdo example of the things they want done: 为了在登录屏幕上回答问题,我展示了UX团队的图像,希望此处某些更改是他们想要完成的事情的一个puesdo示例:

在此处输入图片说明

Remember the two products share almost the entire same code. 请记住,这两个产品几乎共享整个相同的代码。 so in one viewController UI the login screen is slightly different. 因此在一个viewController UI中,登录屏幕略有不同。 How can i achieve this cleanly ? 我怎样才能做到这一点? I could do something like this in the viewController.m: 我可以在viewController.m中执行以下操作:

//puedoCode
if(mySecondTarget){
moveButtonDown();
changeSpacingBetweenEntities();
//etc
}

but this spead all over my code is awful as it ties the UI logic to the code. 但这遍及我的代码非常糟糕,因为它将UI逻辑与代码联系在一起。 What i really wish i could do is make the viewControllers inside the storyboard localized per my product. 我真正希望我能做的是使故事板中的viewControllers按产品进行本地化。 then i could have a single login screens for each target. 那么我可以为每个目标设置一个登录屏幕。 But my team does not want to localize a storyboard file. 但是我的团队不想本地化故事板文件。 We want to keep the same storyboard file as its shared with another team we forked off and we want there updates. 我们希望与分叉的另一个团队保持相同的故事板文件,并希望在那里进行更新。

"Localizing" is a term that means translating to other languages. “本地化”是指翻译成其他语言的术语。

I agree that you're best off having a custom storyboard per product - share the ViewController code and give each a custom look. 我同意最好在每个产品上都有一个自定义情节提要-共享ViewController代码并给每个外观一个自定义的外观。 If it were just colors & fonts I'd say look at NUI, but since you also have layout changes your code is going to get messy adjusting everything per product. 如果只是颜色和字体,我会说一下NUI,但是由于您还进行了布局更改,因此您的代码将变得混乱,无法调整每个产品的所有功能。 At that point you may as well abandon storyboards and create the other product's UI all in code (not ideal IMHO, I'd rather use storyboards!) 到那时,您也可以放弃情节提要,而以代码创建其他产品的UI(这不是理想的恕我直言,我宁愿使用情节提要!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM