Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // Lesson3
- //
- // Created by Alexey Levanov on 11.01.17.
- // Copyright © 2017 AlexeyLevanov. All rights reserved.
- //
- #import "ViewController.h"
- #import "PhoneBookCell.h"
- #define VIEW_HEIGHT 100
- #define TAG 1000
- @interface ViewController () <UITableViewDelegate, UITableViewDataSource>
- @end
- @implementation ViewController
- {
- UIButton *button;
- UILabel *label;
- UITableView *testTableView;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self setupTableView];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- #pragma mark - UI
- - (void)createUI
- {
- self.view.backgroundColor = [UIColor greenColor];
- label = [[UILabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, self.view.frame.size.width, 50)];
- label.textAlignment = NSTextAlignmentCenter;
- label.text = @"Нажми на кнопку";
- label.textColor = [UIColor whiteColor];
- [self.view addSubview:label];
- button = [UIButton buttonWithType:UIButtonTypeCustom];
- button.frame = CGRectMake(0, 0, self.view.frame.size.width, 40);
- button.backgroundColor = [UIColor colorWithRed:213/255.0 green:112/255.0 blue:207/255.0 alpha:1];
- [button setTitle:@"Кнопка" forState:UIControlStateNormal];
- [button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button];
- }
- - (void)setupTableView
- {
- testTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
- testTableView.delegate = self;
- testTableView.dataSource = self;
- [self.view addSubview:testTableView];
- }
- #pragma mark - actions
- - (void)buttonPressed
- {
- label.center = CGPointMake(self.view.center.x, 500);
- label.backgroundColor = [UIColor redColor];
- label.text = @"Кнопка нажата";
- UIView *tempView;
- for (int i=0; i<self.view.subviews.count; i++)
- {
- UIView *view = self.view.subviews[i];
- if (view.tag == TAG)
- view.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];
- }
- if (!tempView)
- {
- tempView = [[UIView alloc] initWithFrame:CGRectMake(self.view.center.x - VIEW_HEIGHT/2, self.view.center.y - VIEW_HEIGHT/2, VIEW_HEIGHT, VIEW_HEIGHT)];
- tempView.tag = TAG;
- tempView.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];
- [self.view addSubview:tempView];
- }
- }
- #pragma mark - UITableView Delegate/DataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 10;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- PhoneBookCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:@"testCell"];
- if (!tableViewCell)
- tableViewCell = [[PhoneBookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"testCell"];
- tableViewCell.textLabel.text = @"Номер строки";
- [tableView setNeedsLayout];
- return tableViewCell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 80.0f;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement