2012年3月28日 星期三

如何製作圓角tableview, 加上textfield


    tableview.dataSource = self;
    tableview.delegate = self;
   
    //tableview 圓角 邊框 分隔線 coustom
    //圓角
    tableview.layer.cornerRadius = 13.0;
    tableview.layer.masksToBounds = YES;
    //分隔線
    [self.tv setSeparatorColor:[UIColor lightGrayColor]];
    //邊框
    tableview.layer.borderWidth = 1;
    tableview.layer.borderColor = [[UIColor lightGrayColor] CGColor];
   

    接著製作cell  並在裡面加上textfield
   
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [self.tv dequeueReusableCellWithIdentifier:CellIdentifier];
   
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    // Configure the cell...
    if([indexPath row]==0){

        //這是原本的cell text label

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSString *tmp = [defaults objectForKey:@"question"];
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
        cell.textLabel.text = [NSString stringWithFormat:@"%@%@", @"密碼保護問題 : ", tmp];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }else if ([indexPath row]==2) {

        /這是textfield      

        u3 = [[UITextField alloc] initWithFrame:CGRectMake(9.5, 10, 300, 60)];
        u3.placeholder = @"新密碼";
        u3.returnKeyType = UIReturnKeyDone;
        u3.delegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell addSubview:u3];      
    }

    依此類推......

}

沒有留言: