-
-
Save arkan/5635018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code inspired from http://jainmarket.blogspot.com/2009/05/creating-custom-table-view-cell.html | |
class CustomCell < UITableViewCell | |
attr_accessor :primaryLabel | |
attr_accessor :secondaryLabel | |
def createLabels | |
@primaryLabel = UILabel.alloc.init | |
@primaryLabel.textAlignment = UITextAlignmentLeft | |
@primaryLabel.font = UIFont.systemFontOfSize(14) | |
@secondaryLabel = UILabel.alloc.init | |
@secondaryLabel.textAlignment = UITextAlignmentLeft | |
@secondaryLabel.font = UIFont.systemFontOfSize(8) | |
self.contentView.addSubview(@primaryLabel) | |
self.contentView.addSubview(@secondaryLabel) | |
self | |
end | |
def layoutSubviews | |
super | |
contentRect = self.contentView.bounds | |
boundsX = contentRect.origin.x | |
@primaryLabel.frame = CGRectMake(boundsX+70, 5, 200, 25) | |
@secondaryLabel.frame = CGRectMake(boundsX+70, 30, 100, 15) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TweetListController < UITableViewController | |
#... | |
CELLID = "CellIdentifier" | |
def tableView(tableView, cellForRowAtIndexPath:indexPath) | |
cell = tableView.dequeueReusableCellWithIdentifier(CELLID) || begin | |
cell = CustomCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:CELLID) | |
cell.createLabels | |
cell | |
end | |
tweet = @tweets[indexPath.row] | |
cell.primaryLabel.text = tweet.username | |
cell.secondaryLabel.text = tweet.text | |
cell | |
end | |
#... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment