UI第十天

一些概念:

1.//UITextView 它可以用做输入,也可以用作显示信息,当用作输入的时候,如果一行信息显示不下的时候,它会自动换行,它是继承自UIScrollView

    self.view.backgroundColor = [UIColor grayColor];

    

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(40, 100, 200, 40)];

    //设置预填信息

    textView.text = @"";

    //设置文字颜色

    textView.textColor = [UIColor redColor];

    //在这个地方设置 x y width 是无用的 只用设置高度才有用

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 80)];

    

    view.backgroundColor = [UIColor redColor];

    //只弹出视图 不弹出键盘

//    textView.inputView = view;

    //弹出键盘和视图

    textView.inputAccessoryView = view;

    //成为第一响应者

    [textView becomeFirstResponder];

    //设置键盘样式

    textView.keyboardType = UIKeyboardTypeNumberPad;

    //设置return键样式

    textView.returnKeyType = UIReturnKeyGo;

    //设置textView是否能够进行输入    YES可以输入 默认  NO不能输入

    textView.editable = YES;

    //设置textView识别的数据类型     手机号  链接  地理位置

    //这个属性有作用的前提条件是上面的editable关闭

    textView.dataDetectorTypes = UIDataDetectorTypeAll;

    

    textView.delegate = self;

    

    [self.view addSubview:textView];

    //注意点:textView的上下左右会空出8个单位的空白,在计算位置的时候需要计算进去


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

    NSLog(@"%ld ----%@",range.location,text);

//    if (textView.text.length > 10)

//    {

//        return NO;

//    }

    return YES;//设为NO就输不进去了

}


//做限制输入功能

- (void)textViewDidChange:(UITextView *)textView

{

    NSString *str = textView.text;

    if (str.length > 10)

    {

        str = [str substringToIndex:10];

    }

    textView.text = str;

}


2. UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];

    tableView.delegate = self;

    tableView.dataSource = self;

    tableView.editing = YES;

    //设置cell的高度 默认高度为44

//    tableView.rowHeight = 60;

    [self.view addSubview:tableView];

    

//    tableView.scrollsToTop = NO;//点击状态栏回到顶部

//    tableView.bounces = NO;//弹性


2.viewController先遵守协议

<UITableViewDelegate,UITableViewDataSource>

#pragma mark ---设置tableView的分组数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return dataArray.count;

}


#pragma mark ---设置tableView的分组中的cell的数量***

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [dataArray[section] count];

}


#pragma mark ---创建cell并且给cell赋值***

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    //建立标示符  static 只创建一次

   static NSString *cellID = @"cellID";

    //从复用池中取cell

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

    static int i = 0;

    //如果为空 那么就创建cell

    if(cell == nil)

    {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];

        i++;

    }

    NSLog(@"%d",i);

//    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    //二维数组下标唯一确定cell

    NSString *str = dataArray[indexPath.section][indexPath.row];

    cell.textLabel.text = [NSString stringWithFormat:@"section:%ld----row:%ld---%@",indexPath.section,indexPath.row,str];

//    UITableViewCellStyleSubtitle是使用cell.detailTextLabel的前提

//    cell.detailTextLabel

    

    return cell;

}


#pragma mark ---设置cell的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.section == 0 && indexPath.row == 1)

    {

        return 100;

    }

    else

    {

        return 44;

    }

}


#pragma mark ---设置分组的头部标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    NSArray *array = @[@"忍者",@"约德尔人",@"女神"];

    return array[section];

}


#pragma mark ---设置分组的尾部标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    return [NSString stringWithFormat:@"%ld",section];

}


#pragma mark ---设置头部标题高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 40;

}


#pragma mark ---设置尾部标题高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 60;

}


#pragma mark ---自定义头部视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

    UILabel *label = [[UILabel alloc] init];

    label.text = [NSString stringWithFormat:@"%ld",section];

    label.backgroundColor = [UIColor yellowColor];

    return label;

}


#pragma mark ---自定义尾部视图

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

    UILabel *label = [[UILabel alloc] init];

    label.text = [NSString stringWithFormat:@"%ld",section];

    label.backgroundColor = [UIColor redColor];

    return label;

}


#pragma mark ---滑动删除

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    [dataArray[indexPath.section] removeObjectAtIndex:indexPath.row];

    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

}


#pragma mark ---设置删除按钮的标题

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return @"删除";

}


#pragma mark ---移动cell

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{


    NSString *str = dataArray[sourceIndexPath.section][sourceIndexPath.row];

    

    [dataArray[destinationIndexPath.section] insertObject:str atIndex:destinationIndexPath.row];

    

    [dataArray[sourceIndexPath.section] removeObjectAtIndex:sourceIndexPath.row];

}


3.block:

(1).typedef void (^ColorBlock)(UIColor *color) ;


@property (copy,nonatomic)ColorBlock myBlock;


(2)

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    if (self.myBlock)

    {

        self.myBlock([UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0]);

    }

    [self dismissViewControllerAnimated:YES completion:nil];

}


(3) 当执行下面的代码时,会调用(2)

vc2.myBlock = ^(UIColor *color){

        self.view.backgroundColor = color;

    };


一些实用方法:

1.快速跳页面:

(1)调到指定:

[self presentViewController:vc3 animated:NO completion:nil];

(2)返回上一级:

[self dismissViewControllerAnimated:NO completion:nil];



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值