Skip to content

Instantly share code, notes, and snippets.

@feighter09
Created August 23, 2016 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feighter09/a2c008b1ac2e88cd8ccf4245c1b40f41 to your computer and use it in GitHub Desktop.
Save feighter09/a2c008b1ac2e88cd8ccf4245c1b40f41 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad
{
[super viewDidLoad];
_multipeerController = [MultipeerController.alloc init];
_multipeerController.delegate = self;
[_multipeerController start];
_graphManager = [GraphManager.alloc init];
_graphManager.delegate = self;
_myPeerID = [MCPeerID.alloc init];
_selectedPeer = -1;
// Do any additional setup after loading the view, typically from a nib.
CGFloat screenWidth = CGRectGetWidth(self.view.bounds);
CGFloat screenHeight = CGRectGetHeight(self.view.bounds);
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Conversations", @"Reachable"]];
[segmentedControl sizeToFit];
segmentedControl.frame = CGRectMake(screenWidth / 2 - segmentedControl.bounds.size.width / 2, 8, CGRectGetWidth(segmentedControl.bounds), CGRectGetHeight(segmentedControl.bounds));
segmentedControl.selectedSegmentIndex = 1;
[segmentedControl addTarget:self
action:@selector(tabTapped:)
forControlEvents:UIControlEventValueChanged];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 64)];
navBar.items = @[self.navigationItem];
self.navigationItem.titleView = segmentedControl;
[self.view addSubview:navBar];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
tap.delegate = self;
[self.view addGestureRecognizer:tap];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, screenHeight / 2 + 50, screenWidth, screenHeight / 2 - 50)];
[_tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"cell"];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
_composerTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, screenHeight / 2, screenWidth - 60, 50)];
_composerTextField.placeholder = @"Type a message...";
_composerTextField.delegate = self;
[self.view addSubview:_composerTextField];
_composerSendButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_composerSendButton setTitle:@"Send" forState:UIControlStateNormal];
_composerSendButton.backgroundColor = [UIColor blueColor];
_composerSendButton.titleLabel.textColor = [UIColor whiteColor];
_composerSendButton.titleLabel.textAlignment = NSTextAlignmentCenter;
_composerSendButton.frame = CGRectMake(screenWidth - 50, screenHeight /2, 50, 50);
[_composerSendButton addTarget:self action:@selector(sendBtnPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_composerSendButton];
// _restartMultipeerButton = [UIButton buttonWithType:UIButtonTypeSystem];
// [_restartMultipeerButton setTitle:@"Restart Multipeer" forState:UIControlStateNormal];
// [_restartMultipeerButton sizeToFit];
// CGSize size = _restartMultipeerButton.bounds.size;
// _restartMultipeerButton.frame = CGRectMake(screenWidth / 2 - size.width / 2, 10, size.width, size.height);
// [_restartMultipeerButton addTarget:self action:@selector(restartMultipeerButtonPressed) forControlEvents:UIControlEventTouchUpInside];
// [self.view addSubview:_restartMultipeerButton];
_nameTextField = [UITextField new];
_nameTextField.placeholder = @"Name";
_nameTextField.delegate = self;
_nameTextField.frame = CGRectMake(screenWidth / 2 - 100, 70, 200, 20);
[self.view addSubview:_nameTextField];
_nameResetButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_nameResetButton setTitle:@"Set Name" forState:UIControlStateNormal];
[_nameResetButton sizeToFit];
CGSize size = _nameResetButton.bounds.size;
_nameResetButton.frame = CGRectMake(screenWidth / 2 - size.width / 2, 100, size.width, size.height);
[_nameResetButton addTarget:self action:@selector(nameResetButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_nameResetButton];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment