2015-12-14 50 views
2

我无法让文字留在屏幕宽度内。我缩小了文字,不想让它有任何的缩小(请参见下文):用户界面通过故事板或以编程方式?

enter image description here

它会更好,在具有自适应布局,适合在屏幕方面,而是要使用故事板以编程方式执行它?

这是我现有的左视图控制器代码:

import UIKit 

protocol LeftViewControllerDelegate { 
    func leftUnitSelected(index: WUnit) 

    func leftDataChanged(text: String) 
} 

class LeftViewController: UIViewController,UITableViewDelegate,UITextFieldDelegate { 

    @IBOutlet weak var leftTextField: UITextField! 
    var dataArray: [String] = [] 
    var delegate: LeftViewControllerDelegate? 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.dataArray = ["Litre", "MilliLitre", "Fluid Ounce (US)", "Fluid Ounce (UK)", "Teaspoon (US)", "Teaspoon (UK)", "Tablespoon (US)", "Tablespoon (UK)", "Cup (US)", "Cup (UK)", "Pint (US)", "Pint (UK)", "Quart (US)", "Quart (UK)", "Gallon (US)", "Gallon (UK)"] 
     NSNotificationCenter.defaultCenter().addObserver(self, selector: "textFieldTextDidChangeOneCI:", name: UITextFieldTextDidChangeNotification, object: self.leftTextField) 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    //MARK: UITableView Datasource 

    func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return self.dataArray.count 
    } 


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
     cell.textLabel!.text = self.dataArray[indexPath.row] 
     cell.textLabel!.font = UIFont(name: cell.textLabel!.font.fontName, size:12) // Change the font size as per your requirement 
     cell.imageView!.image = UIImage(named: "20x20_empty-round-radiobutton-choice-ui") 
     return cell 
    } 



    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
     return 32 
    } 

    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 
     let cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)! 
     cell.imageView!.image = UIImage(named: "20x20_empty-round-radiobutton-choice-ui") 
    } 

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     let cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)! 
     cell.imageView!.image = UIImage(named: "20x20_round-choice-radiobutton-ui") 
     if let delegate = delegate { 
      delegate.leftUnitSelected(WUnit(rawValue: indexPath.row)!) 
     } 
    } 

    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String { 
     return "From" 
    } 

    //MARK: 

    func setText(text: String) { 
     self.leftTextField.text = text 
    } 

    func textFieldTextDidChangeOneCI(notification: NSNotification) { 
     let textfield: UITextField = notification.object! as! UITextField 
     if Double(textfield.text!) > 0.0 { 
      if let delegate = delegate { 
       delegate.leftDataChanged(textfield.text!) 
      } 
     } 
    } 

    func text() -> String { 
     return self.leftTextField.text! 
    } 
} 

感谢您的任何建议!

+0

目前有些不清楚(视觉上)您现在拥有什么样的结果,但作为一般规则 - 尝试使用“故事板” '尽可能多 - **“少代码=少bug”** –

+0

谢谢。我的下一个问题是,我将如何将我目前的代码转换为Storyboard布局? – mhs5819

回答

1

基于故事板的方法处理许多必要的细节以支持自适应UI。

除此之外,你可以重新考虑你的设计。这不是iOS的本地设计,因为iOS没有单选按钮或水平压缩的拆分表格视图。

您可以查看现有的单位换算应用,以了解他们如何让用户选择单元。

一个建议是只要求一个单位(一次)。一旦你知道一个单位,你可以预测第二个单位,以保存用户不必选择可能的选择。无论哪种方式,您都应该考虑特质类以及您的UI如何适应不同设备(例如,模式,弹出窗口,分割视图)。

至于用户界面,你可以通过一个选择器,一个tableview的复选标记附件视图,或一个自定义控件。只要记住用户对用户界面越熟悉和直观,用户就越不可能被如何使用你的应用程序所困惑。

您呈现的选择越少,用户就越好。例如,如果有人位于英国,他们可能不需要转换为美国的度量。如果您绝对需要提供所有可能的选择,请考虑将度量分成不同的部分(按国家或系统)。

+0

感谢您提出这些建议。我已经找到了一个关于使用两个并排选择器视图进行单位转换的教程,比使用代码简单得多。 – mhs5819

1

看起来你已经在桌面单元格&中设计了UI,你正在以编程方式设置它的高度。你可以在属性检查器中将界面生成器中的标签的lines属性设置为适当的行,以便相应地调整你的文本。确保从尺寸检查器中增加桌面视图行的大小,以便您的单元格相应地适合

相关问题