daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @interface FontPickerSheet : UIView <UITableViewDataSource, UITableViewDelegate>
  2. {
  3.     UILabel *title;
  4.     UITableView *tableView;
  5.     NSString *selection;
  6. }
  7. @property (nonatomic, retain) NSString *selection;
  8. @end
  9.  
  10. @implementation FontPickerSheet
  11. @synthesize selection;
  12.  
  13. #pragma mark UITableViewDataSource Methods
  14.  
  15. // Only one section in this table
  16. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  17. {
  18.     return 1;
  19. }
  20.  
  21. // One row for each family font name
  22. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  23. {
  24.     return [[UIFont    familyNames] count];
  25. }
  26.  
  27. // Return a cell for the ith row
  28. - (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  29. {
  30.     UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier:@"any-cell"];
  31.  
  32.     if (cell == nil) {
  33.         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
  34.     }
  35.     // Set up the cell
  36.     cell.text = [[UIFont familyNames] objectAtIndex:[indexPath row]];
  37.     return cell;
  38. }
  39.  
  40. #pragma mark UITableViewDelegateMethods
  41.  
  42. // Respond to user selection
  43. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) newIndexPath
  44. {
  45.     selection = [[[UIFont familyNames] objectAtIndex:[newIndexPath row]] retain];
  46. }
  47.  
  48. #pragma mark FontPickerSheet customization
  49.  
  50. - (FontPickerSheet *) initWithFrame: (CGRect) rect
  51. {
  52.     rect.origin.y = 0.0f - rect.size.height; // Place above status bar
  53.     self = [super initWithFrame:rect];
  54.     [self setAlpha:0.9];
  55.     [self setBackgroundColor:sysBlueColor(0.4f)];
  56.  
  57.     // Add button
  58.     UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(220.0f, 200.0f, 80.0f, 32.0f)];
  59.     [button setBackgroundImage:[UIImage imageNamed:@"whiteButton.png"] forState:UIControlStateNormal];
  60.     [button setTitle:@"Okay" forState: UIControlStateHighlighted];
  61.     [button setTitle:@"Okay" forState: UIControlStateNormal];
  62.     [button setFont:[UIFont boldSystemFontOfSize:14.0f]];
  63.     [button addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchUpInside];
  64.     [self addSubview:button];
  65.  
  66.     // Add title
  67.     title = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 8.0f, 320.0f, 32.0f)];
  68.     title.text = @"Please Select a Font";
  69.     title.textAlignment = UITextAlignmentCenter;
  70.     title.textColor = [UIColor whiteColor];
  71.     title.backgroundColor = [UIColor clearColor];
  72.     title.font = [UIFont boldSystemFontOfSize:20.0f];
  73.     [self addSubview:title];
  74.     [title release];
  75.  
  76.     // Add border for the table
  77.     CGRect bounds = CGRectMake(20.0f, 40.0f, 280.0f, 200.0f - 48.0f);
  78.     UIView *borderView = [[UIView alloc] initWithFrame:bounds];
  79.     [borderView setBackgroundColor:sysBlueColor(0.55f)];
  80.     [self addSubview:borderView];
  81.     [borderView release];
  82.  
  83.     // Add table
  84.     tableView = [[UITableView alloc] initWithFrame:CGRectInset(bounds, 4.0f, 4.0f) style:UITableViewStylePlain];
  85.     tableView.backgroundColor = [UIColor whiteColor];
  86.     tableView.delegate = self;
  87.     tableView.dataSource = self;
  88.     [tableView reloadData];
  89.     [self addSubview:tableView];
  90.     [tableView release];
  91.  
  92.     return self;
  93. }
  94.  
  95. - (void) removeView
  96. {
  97.     [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
  98.  
  99.     // Scroll away the overlay
  100.     CGContextRef context = UIGraphicsGetCurrentContext();
  101.     [UIView beginAnimations:nil context:context];
  102.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  103.     [UIView setAnimationDuration:0.5];
  104.  
  105.     CGRect rect = [self frame];
  106.     rect.origin.y = 0.0f - rect.size.height;
  107.     [self setFrame:rect];
  108.  
  109.     // Complete the animation
  110.     [UIView commitAnimations];
  111. }
  112.  
  113. - (void) presentView
  114. {
  115.     selection = NULL;
  116.  
  117.     // Scroll in the overlay
  118.     CGContextRef context = UIGraphicsGetCurrentContext();
  119.     [UIView beginAnimations:nil context:context];
  120.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  121.     [UIView setAnimationDuration:0.5];
  122.  
  123.     CGRect rect = [self frame];
  124.     rect.origin.y = 0.0f;
  125.     [self setFrame:rect];
  126.  
  127.     // Complete the animation
  128.     [UIView commitAnimations];
  129. }
  130.  
  131. -(void) dealloc
  132. {
  133.     [title release];
  134.     [tableView release];
  135.     [super dealloc];
  136. }
  137. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top