Skip to content

Instantly share code, notes, and snippets.

@TheKidCoder
Created January 19, 2015 19:45

Revisions

  1. TheKidCoder created this gist Jan 19, 2015.
    33 changes: 33 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    def email_text_field
    return @email_text_field if @email_text_field

    @email_text_field = UITextField.alloc.initWithFrame([[0, 0], [225, 40]])
    @email_text_field.center = CGPointMake(self.view.frame.size.width / 2, (self.view.frame.size.height / 2) - 60)
    @email_text_field.placeholder = "[email protected]"
    @email_text_field.borderStyle = UITextBorderStyleRoundedRect

    @email_text_field
    end

    #Smaller variable names...
    def email_text_field
    return @email_text_field if @email_text_field

    @email_text_field = UITextField.alloc.initWithFrame([[0, 0], [225, 40]])
    @email_text_field.tap do |tf|
    tf.center = CGPointMake(self.view.frame.size.width / 2, (self.view.frame.size.height / 2) - 60)
    tf.placeholder = "[email protected]"
    tf.borderStyle = UITextBorderStyleRoundedRect
    end

    @email_text_field
    end

    # Memoize all in one.
    def email_text_field
    return @email_text_field ||= UITextField.alloc.initWithFrame([[0, 0], [225, 40]]).tap do |tf|
    tf.center = CGPointMake(self.view.frame.size.width / 2, (self.view.frame.size.height / 2) - 60)
    tf.placeholder = "[email protected]"
    tf.borderStyle = UITextBorderStyleRoundedRect
    end
    end