|
1 | | -(function() { |
2 | | - var ButtonsViewController = JSB.Class.define('ButtonsViewController : UITableViewController', { |
3 | | - viewDidLoad: function() { |
4 | | - self.navigationItem.title = 'Buttons'; |
5 | | - |
6 | | - this.dataSourceArray = []; |
7 | | - |
8 | | - var buttonBackground = UIImage.imageNamed('whiteButton'); |
9 | | - var buttonBackgroundPressed = UIImage.imageNamed('blueButton'); |
10 | | - |
11 | | - var frame = {x: 0, y: 5, width: 106, height: 40}; |
12 | | - |
13 | | - var button = UIButton.alloc().initWithFrame(frame); |
14 | | - |
15 | | - button.contentVerticalAlignment = 0; |
16 | | - button.contentHorizontalAlignment = 0; |
17 | | - button.setTitleForState('Gray', 0); |
18 | | - button.setTitleColorForState(UIColor.blackColor(), 0); |
19 | | - |
20 | | - var newImage = buttonBackground.stretchableImageWithLeftCapWidthTopCapHeight(12, 0); |
21 | | - button.setBackgroundImageForState(newImage, 0); |
22 | | - |
23 | | - var newPressedImage = buttonBackgroundPressed.stretchableImageWithLeftCapWidthTopCapHeight(12, 0); |
24 | | - button.setBackgroundImageForState(newPressedImage, 1 << 0); |
25 | | - |
26 | | - button.backgroundColor = UIColor.clearColor(); |
27 | | - button.tag = 1; |
28 | | - |
29 | | - dataSourceArray.push({ |
30 | | - sectionTitleKey: 'UIButton', |
31 | | - labelKey: 'Background Image', |
32 | | - sourceKey: 'ButtonsViewController.m:\r(UIButton *)grayButton', |
33 | | - viewKey: button |
34 | | - }); |
35 | | - }, |
36 | | - numberOfSectionsInTableView: function(tableView) { |
37 | | - return dataSourceArray.length; |
38 | | - }, |
39 | | - tableViewNumberOfRowsInSection: function(tableView, section) { |
40 | | - return 2; |
41 | | - }, |
42 | | - tableViewTitleForHeaderInSection: function(tableView, section) { |
43 | | - return dataSourceArray[section]['sectionTitleKey']; |
44 | | - }, |
45 | | - tableViewHeightForRowAtIndexPath: function(tableView, indexPath) { |
46 | | - return (indexPath.row == 0) ? 50 : 38; |
47 | | - }, |
48 | | - tableViewCellForRowAtIndexPath: function(tableView, indexPath) { |
49 | | - if (indexPath.row == 0) { |
50 | | - var cell = UITableViewCell.alloc().initWithStyleReuseIdentifier(0, 'DisplayCellID'); |
51 | | - cell.selectionStyle = 0; |
52 | | - |
53 | | - var viewToRemove = null; |
54 | | - viewToRemove = cell.contentView.viewWithTag(1); |
55 | | - if (viewToRemove) { |
56 | | - viewToRemove.removeFromSuperview(); |
57 | | - } |
58 | | - |
59 | | - cell.textLabel.text = dataSourceArray[indexPath.section]['labelKey']; |
60 | | - var button = dataSourceArray[indexPath.section]['viewKey']; |
61 | | - |
62 | | - var newFrame = button.frame; |
63 | | - newFrame.x = cell.contentView.frame.width - newFrame.width - 10; |
64 | | - button.frame = newFrame; |
65 | | - |
66 | | - button.autoresizingMask = 1 << 0; |
67 | | - |
68 | | - cell.contentView.addSubview(button); |
69 | | - |
70 | | - return cell; |
71 | | - } else { |
72 | | - var cell = UITableViewCell.alloc().initWithStyleReuseIdentifier(0, 'SourceCellID'); |
73 | | - cell.selectionStyle = 0; |
74 | | - |
75 | | - cell.textLabel.opaque = false; |
76 | | - cell.textLabel.textAlignment = 1; |
77 | | - cell.textLabel.textColor = UIColor.grayColor(); |
78 | | - cell.textLabel.numberOfLines = 2; |
79 | | - cell.textLabel.highlightedTextColor = UIColor.blackColor(); |
80 | | - cell.textLabel.font = UIFont.systemFontOfSize(12); |
81 | | - cell.textLabel.text = menuList[indexPath.section]['sourceKey']; |
82 | | - |
83 | | - return cell; |
| 1 | +var ButtonsViewController = JSB.define('ButtonsViewController : UITableViewController', { |
| 2 | + viewDidLoad: function() { |
| 3 | + self.navigationItem.title = 'Buttons'; |
| 4 | + |
| 5 | + this.dataSourceArray = []; |
| 6 | + |
| 7 | + var buttonBackground = UIImage.imageNamed('whiteButton'); |
| 8 | + var buttonBackgroundPressed = UIImage.imageNamed('blueButton'); |
| 9 | + |
| 10 | + var frame = {x: 0, y: 5, width: 106, height: 40}; |
| 11 | + |
| 12 | + var button = UIButton.alloc().initWithFrame(frame); |
| 13 | + |
| 14 | + button.contentVerticalAlignment = 0; |
| 15 | + button.contentHorizontalAlignment = 0; |
| 16 | + button.setTitleForState('Gray', 0); |
| 17 | + button.setTitleColorForState(UIColor.blackColor(), 0); |
| 18 | + |
| 19 | + var newImage = buttonBackground.stretchableImageWithLeftCapWidthTopCapHeight(12, 0); |
| 20 | + button.setBackgroundImageForState(newImage, 0); |
| 21 | + |
| 22 | + var newPressedImage = buttonBackgroundPressed.stretchableImageWithLeftCapWidthTopCapHeight(12, 0); |
| 23 | + button.setBackgroundImageForState(newPressedImage, 1 << 0); |
| 24 | + |
| 25 | + button.backgroundColor = UIColor.clearColor(); |
| 26 | + button.tag = 1; |
| 27 | + |
| 28 | + dataSourceArray.push({ |
| 29 | + sectionTitleKey: 'UIButton', |
| 30 | + labelKey: 'Background Image', |
| 31 | + sourceKey: 'ButtonsViewController.m:\r(UIButton *)grayButton', |
| 32 | + viewKey: button |
| 33 | + }); |
| 34 | + }, |
| 35 | + numberOfSectionsInTableView: function(tableView) { |
| 36 | + return dataSourceArray.length; |
| 37 | + }, |
| 38 | + tableViewNumberOfRowsInSection: function(tableView, section) { |
| 39 | + return 2; |
| 40 | + }, |
| 41 | + tableViewTitleForHeaderInSection: function(tableView, section) { |
| 42 | + return dataSourceArray[section]['sectionTitleKey']; |
| 43 | + }, |
| 44 | + tableViewHeightForRowAtIndexPath: function(tableView, indexPath) { |
| 45 | + return (indexPath.row == 0) ? 50 : 38; |
| 46 | + }, |
| 47 | + tableViewCellForRowAtIndexPath: function(tableView, indexPath) { |
| 48 | + if (indexPath.row == 0) { |
| 49 | + var cell = UITableViewCell.alloc().initWithStyleReuseIdentifier(0, 'DisplayCellID'); |
| 50 | + cell.selectionStyle = 0; |
| 51 | + |
| 52 | + var viewToRemove = null; |
| 53 | + viewToRemove = cell.contentView.viewWithTag(1); |
| 54 | + if (viewToRemove) { |
| 55 | + viewToRemove.removeFromSuperview(); |
84 | 56 | } |
| 57 | + |
| 58 | + cell.textLabel.text = dataSourceArray[indexPath.section]['labelKey']; |
| 59 | + var button = dataSourceArray[indexPath.section]['viewKey']; |
| 60 | + |
| 61 | + var newFrame = button.frame; |
| 62 | + newFrame.x = cell.contentView.frame.width - newFrame.width - 10; |
| 63 | + button.frame = newFrame; |
| 64 | + |
| 65 | + button.autoresizingMask = 1 << 0; |
| 66 | + |
| 67 | + cell.contentView.addSubview(button); |
| 68 | + |
| 69 | + return cell; |
| 70 | + } else { |
| 71 | + var cell = UITableViewCell.alloc().initWithStyleReuseIdentifier(0, 'SourceCellID'); |
| 72 | + cell.selectionStyle = 0; |
| 73 | + |
| 74 | + cell.textLabel.opaque = false; |
| 75 | + cell.textLabel.textAlignment = 1; |
| 76 | + cell.textLabel.textColor = UIColor.grayColor(); |
| 77 | + cell.textLabel.numberOfLines = 2; |
| 78 | + cell.textLabel.highlightedTextColor = UIColor.blackColor(); |
| 79 | + cell.textLabel.font = UIFont.systemFontOfSize(12); |
| 80 | + cell.textLabel.text = menuList[indexPath.section]['sourceKey']; |
| 81 | + |
| 82 | + return cell; |
85 | 83 | } |
86 | | - }); |
87 | | -})(); |
| 84 | + } |
| 85 | +}); |
88 | 86 |
|
| 87 | +JSB.exports = ButtonsViewController; |
0 commit comments