Commit 8d923b3
Changed files (1)
app
controllers
app/controllers/restaurant_controller.rb
@@ -4,13 +4,8 @@ class RestaurantController < UIViewController
self.title = "Restaurant"
self.view.backgroundColor = UIColor.whiteColor
- @text_field = UITextField.alloc.initWithFrame [[0,0], [160, 26]]
- @text_field.placeholder = ""
- @text_field.textAlignment = UITextAlignmentCenter
- @text_field.autocapitalizationType = UITextAutocapitalizationTypeNone
- @text_field.borderStyle = UITextBorderStyleRoundedRect
- @text_field.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2 - 100)
- self.view.addSubview @text_field
+ @text_field = Build.text_field([[0,0], [160, 26]]).centered_within(self.view).build
+ self.addView(@text_field)
@add = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@add.setTitle("Add Restaurant", forState:UIControlStateNormal)
@@ -33,4 +28,30 @@ class RestaurantController < UIViewController
end
end
end
+
+ def addView(view)
+ self.view.addSubview(view)
+ end
+end
+
+class Build
+ def self.text_field(coordinates)
+ TextBoxBuilder.new(coordinates)
+ end
+end
+
+class TextBoxBuilder
+ def initialize(coordinates)
+ @text_field = UITextField.alloc.initWithFrame(coordinates)
+ @text_field.autocapitalizationType = UITextAutocapitalizationTypeNone
+ @text_field.borderStyle = UITextBorderStyleRoundedRect
+ end
+ def centered_within(view)
+ @text_field.textAlignment = UITextAlignmentCenter
+ @text_field.center = CGPointMake(view.frame.size.width / 2, view.frame.size.height / 2 - 100)
+ self
+ end
+ def build
+ @text_field
+ end
end