Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Created June 28, 2012 13:16
Show Gist options
  • Save Bodacious/3011313 to your computer and use it in GitHub Desktop.
Save Bodacious/3011313 to your computer and use it in GitHub Desktop.
A handy helper for showing loading cells in iOS Apps with Rubymotion

Here's A handy helper for showing loading cells in iOS Apps with Rubymotion

To use, simply include the class in your project and then from within your controller:

# in my controller

def tableView(tableView, cellForRowAtIndexPath: indexPath)
  # return a loading cell
  LoadingCell.loadingCellWithTableView(self.tableView)
end

Here's how it looks:

Loading Cell

Feel free to modify to suit your needs :-)

~ KatanaCode Ltd. 2012

class LoadingCell < UITableViewCell
CELL_FRAME = [[0,0], [320, 44]]
LABEL_FRAME = [[120, 11], [79, 21]]
ACTIVITY_INDICATOR_FRAME = [[92,11],[20,20]]
LABEL_TEXT = 'Loading...'
def self.loadingCellWithTableView(tableView)
tableView.dequeueReusableCellWithIdentifier(self.class.to_s) || begin
alloc.initWithFrame(CELL_FRAME)
end
end
def reuseIdentifier
self.class.to_s
end
def initWithFrame(frame)
super(frame)
addSubview(activityIndicator)
addSubview(label)
end
def label
@label ||= begin
_label = UILabel.alloc.initWithFrame(LABEL_FRAME)
_label.text = LABEL_TEXT
_label.textColor = UIColor.darkGrayColor
_label.backgroundColor = UIColor.clearColor
_label
end
end
def activityIndicator
@activityIndicator ||= begin
_activityIndicator = UIActivityIndicatorView.alloc.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleGray)
_activityIndicator.frame = ACTIVITY_INDICATOR_FRAME
_activityIndicator.startAnimating
_activityIndicator
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment