ZSSFontsViewController.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // ZSSFontsViewController.m
  3. // ZSSRichTextEditor
  4. //
  5. // Created by Will Swan on 03/09/2016.
  6. // Copyright © 2016 Zed Said Studio. All rights reserved.
  7. //
  8. #import "ZSSFontsViewController.h"
  9. @interface ZSSFontsViewController () <UITableViewDelegate,UITableViewDataSource> {
  10. ZSSFontFamily selectedFontFamily;
  11. }
  12. @end
  13. @implementation ZSSFontsViewController
  14. @synthesize delegate;
  15. #pragma mark - Init Section
  16. + (ZSSFontsViewController *)cancelableFontPickerViewControllerWithFontFamily:(ZSSFontFamily)fontFamily {
  17. return [[ZSSFontsViewController alloc] initWithFontFamily:fontFamily];
  18. }
  19. - (id)initWithFontFamily:(ZSSFontFamily)fontFamily {
  20. self = [super initWithNibName:nil bundle:nil];
  21. if (self) {
  22. _font = fontFamily;
  23. }
  24. return self;
  25. }
  26. #pragma mark - View Did Load Section
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. //Set up navigation
  30. [self setUpNavigation];
  31. //Create table view
  32. [self createTableView];
  33. }
  34. #pragma mark - Set Up View Section
  35. - (void)setUpNavigation {
  36. self.navigationItem.title = @"Fonts";
  37. UIBarButtonItem *buttonItem;
  38. buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
  39. self.navigationItem.leftBarButtonItem = buttonItem;
  40. buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)];
  41. self.navigationItem.rightBarButtonItem = buttonItem;
  42. }
  43. - (void)createTableView {
  44. UITableView *tableView = [[UITableView alloc] init];
  45. tableView.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height);
  46. tableView.delegate = self;
  47. tableView.dataSource = self;
  48. tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  49. [self.view addSubview:tableView];
  50. }
  51. #pragma mark - Table View Section
  52. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  53. return 1;
  54. }
  55. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  56. return 7;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  59. static NSString *CellIdentifier = @"fontCell";
  60. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  61. if (cell == nil) {
  62. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  63. }
  64. float fontSize = 20.0f;
  65. switch (indexPath.row) {
  66. case 0:
  67. cell.textLabel.text = @"Default";
  68. cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:fontSize];
  69. break;
  70. case 1:
  71. cell.textLabel.text = @"Trebuchet";
  72. cell.textLabel.font = [UIFont fontWithName:@"TrebuchetMS" size:fontSize];
  73. break;
  74. case 2:
  75. cell.textLabel.text = @"Verdana";
  76. cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:fontSize];
  77. break;
  78. case 3:
  79. cell.textLabel.text = @"Georgia";
  80. cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:fontSize];
  81. break;
  82. case 4:
  83. cell.textLabel.text = @"Palatino";
  84. cell.textLabel.font = [UIFont fontWithName:@"Palatino-Roman" size:fontSize];
  85. break;
  86. case 5:
  87. cell.textLabel.text = @"Times New Roman";
  88. cell.textLabel.font = [UIFont fontWithName:@"TimesNewRomanPSMT" size:fontSize];
  89. break;
  90. case 6:
  91. cell.textLabel.text = @"Courier New";
  92. cell.textLabel.font = [UIFont fontWithName:@"CourierNewPSMT" size:fontSize];
  93. break;
  94. default:
  95. break;
  96. }
  97. cell.selectionStyle = UITableViewCellSelectionStyleBlue;
  98. return cell;
  99. }
  100. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  101. switch (indexPath.row) {
  102. case 0:
  103. selectedFontFamily = ZSSFontFamilyDefault;
  104. break;
  105. case 1:
  106. selectedFontFamily = ZSSFontFamilyTrebuchet;
  107. break;
  108. case 2:
  109. selectedFontFamily = ZSSFontFamilyVerdana;
  110. break;
  111. case 3:
  112. selectedFontFamily = ZSSFontFamilyGeorgia;
  113. break;
  114. case 4:
  115. selectedFontFamily = ZSSFontFamilyPalatino;
  116. break;
  117. case 5:
  118. selectedFontFamily = ZSSFontFamilyTimesNew;
  119. break;
  120. case 6:
  121. selectedFontFamily = ZSSFontFamilyCourierNew;
  122. break;
  123. default:
  124. break;
  125. }
  126. }
  127. #pragma mark - Navigation Item Interactions Section
  128. - (void)save {
  129. if (self.delegate) {
  130. //HRRGBColor rgbColor = [colorPickerView RGBColor];
  131. [self.delegate setSelectedFontFamily:selectedFontFamily];
  132. }
  133. [self.navigationController popViewControllerAnimated:YES];
  134. }
  135. - (void)save:(id)sender {
  136. [self save];
  137. }
  138. - (void)cancel:(id)sender {
  139. [self.navigationController popViewControllerAnimated:YES];
  140. }
  141. #pragma mark - Memory Warning Section
  142. - (void)didReceiveMemoryWarning {
  143. [super didReceiveMemoryWarning];
  144. }
  145. @end