简体   繁体   中英

Presenting a semi-transparent UITableView from a UIViewController

I'm working on an app that will rely on one main view controller with a row of buttons at the bottom to display other views with information. From one of these buttons I want to present a tableview that presents a list of song titles. This app plays sound files, and I want the user to be able to tap a button, then select a song to be the default song to play. I want to present this tableview with a uiview animation, and I want it to be semi-transparent and only fill a portion of the screen. I've tried creating a UITableViewController and then presenting it from the main view controller like so:

UITableViewController *tableView = [[UITableViewController alloc]init];
[self presentViewController:tableView animated:YES completion:nil];

This presents a view controller that fills the entire screen though, which is not what I want. And changing the view controller's frame at instantiation time doesn't seem to have an effect. I can just animate a UITableView into the main view controller's view, but then I'm not so sure who is supposed to be the delegate and data source. Any suggestions? Thanks in advance.

While adding table view as a subview, u can set its frame size or bound, and display it with animation whatever you like. Yes, you can set delegate and datasource to self while adding .

I use: (in viewDidLoad)

 self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.opaque = NO;

Then in cellForRowAtIndexPath:

cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];

Not sure if this is what you wanted, but it gives you the option to make everything clear. (obviously the alpha would change for your case, but that measures the opacity of the cells)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM