Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface FontPickerSheet : UIView <UITableViewDataSource, UITableViewDelegate>
- {
- UILabel *title;
- UITableView *tableView;
- NSString *selection;
- }
- @property (nonatomic, retain) NSString *selection;
- @end
- @implementation FontPickerSheet
- @synthesize selection;
- #pragma mark UITableViewDataSource Methods
- // Only one section in this table
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- // One row for each family font name
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [[UIFont familyNames] count];
- }
- // Return a cell for the ith row
- - (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier:@"any-cell"];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
- }
- // Set up the cell
- cell.text = [[UIFont familyNames] objectAtIndex:[indexPath row]];
- return cell;
- }
- #pragma mark UITableViewDelegateMethods
- // Respond to user selection
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) newIndexPath
- {
- selection = [[[UIFont familyNames] objectAtIndex:[newIndexPath row]] retain];
- }
- #pragma mark FontPickerSheet customization
- - (FontPickerSheet *) initWithFrame: (CGRect) rect
- {
- rect.origin.y = 0.0f - rect.size.height; // Place above status bar
- self = [super initWithFrame:rect];
- [self setAlpha:0.9];
- [self setBackgroundColor:sysBlueColor(0.4f)];
- // Add button
- UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(220.0f, 200.0f, 80.0f, 32.0f)];
- [button setBackgroundImage:[UIImage imageNamed:@"whiteButton.png"] forState:UIControlStateNormal];
- [button setTitle:@"Okay" forState: UIControlStateHighlighted];
- [button setTitle:@"Okay" forState: UIControlStateNormal];
- [button setFont:[UIFont boldSystemFontOfSize:14.0f]];
- [button addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:button];
- // Add title
- title = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 8.0f, 320.0f, 32.0f)];
- title.text = @"Please Select a Font";
- title.textAlignment = UITextAlignmentCenter;
- title.textColor = [UIColor whiteColor];
- title.backgroundColor = [UIColor clearColor];
- title.font = [UIFont boldSystemFontOfSize:20.0f];
- [self addSubview:title];
- [title release];
- // Add border for the table
- CGRect bounds = CGRectMake(20.0f, 40.0f, 280.0f, 200.0f - 48.0f);
- UIView *borderView = [[UIView alloc] initWithFrame:bounds];
- [borderView setBackgroundColor:sysBlueColor(0.55f)];
- [self addSubview:borderView];
- [borderView release];
- // Add table
- tableView = [[UITableView alloc] initWithFrame:CGRectInset(bounds, 4.0f, 4.0f) style:UITableViewStylePlain];
- tableView.backgroundColor = [UIColor whiteColor];
- tableView.delegate = self;
- tableView.dataSource = self;
- [tableView reloadData];
- [self addSubview:tableView];
- [tableView release];
- return self;
- }
- - (void) removeView
- {
- [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
- // Scroll away the overlay
- CGContextRef context = UIGraphicsGetCurrentContext();
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.5];
- CGRect rect = [self frame];
- rect.origin.y = 0.0f - rect.size.height;
- [self setFrame:rect];
- // Complete the animation
- [UIView commitAnimations];
- }
- - (void) presentView
- {
- selection = NULL;
- // Scroll in the overlay
- CGContextRef context = UIGraphicsGetCurrentContext();
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.5];
- CGRect rect = [self frame];
- rect.origin.y = 0.0f;
- [self setFrame:rect];
- // Complete the animation
- [UIView commitAnimations];
- }
- -(void) dealloc
- {
- [title release];
- [tableView release];
- [super dealloc];
- }
- @end
Add Comment
Please, Sign In to add comment