UI第十天

来源:互联网 发布:建筑工程网络计划图 编辑:程序博客网 时间:2024/05/23 02:07

一些概念:

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

    self.view.backgroundColor = [UIColorgrayColor];

    

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

    //设置预填信息

    textView.text =@"";

    //设置文字颜色

    textView.textColor = [UIColorredColor];

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

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

    

    view.backgroundColor = [UIColorredColor];

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

//    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.viewaddSubview: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;

//    }

    returnYES;//设为NO就输不进去了

}


//做限制输入功能

- (void)textViewDidChange:(UITextView *)textView

{

   NSString *str = textView.text;

   if (str.length >10)

    {

        str = [strsubstringToIndex:10];

    }

    textView.text = str;

}


2. UITableView *tableView = [[UITableViewalloc] initWithFrame:self.view.boundsstyle:UITableViewStyleGrouped];

    tableView.delegate =self;

    tableView.dataSource =self;

    tableView.editing =YES;

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

//    tableView.rowHeight = 60;

    [self.viewaddSubview:tableView];

    

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

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


2.viewController先遵守协议

<UITableViewDelegate,UITableViewDataSource>

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

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    returndataArray.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 = [tableViewdequeueReusableCellWithIdentifier:cellID];

   static int i =0;

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

   if(cell == nil)

    {

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellID];

        i++;

    }

   NSLog(@"%d",i);

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

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

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

    cell.textLabel.text = [NSStringstringWithFormat:@"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 [NSStringstringWithFormat:@"%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 = [[UILabelalloc] init];

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

    label.backgroundColor = [UIColoryellowColor];

   return label;

}


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

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

{

   UILabel *label = [[UILabelalloc] init];

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

    label.backgroundColor = [UIColorredColor];

   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).typedefvoid (^ColorBlock)(UIColor *color) ;


@property (copy,nonatomic)ColorBlock myBlock;


(2)

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

{

   if (self.myBlock)

    {

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

    }

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}


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

vc2.myBlock = ^(UIColor *color){

       self.view.backgroundColor = color;

    };


一些实用方法:

1.快速跳页面:

(1)调到指定:

[selfpresentViewController:vc3 animated:NOcompletion:nil];

(2)返回上一级:

[selfdismissViewControllerAnimated:NOcompletion:nil];



1 0
原创粉丝点击