天天看點

iOS開發筆記--cell最右邊顯示箭頭,字元,自定義分割線

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

{  

    static NSString *CellIdentifier = @"Cell";  

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:  

                             CellIdentifier];  

    if (0 == indexPath.section) {  

        cell = [[[UITableViewCell alloc]  

                initWithStyle:UITableViewCellStyleDefault  

                reuseIdentifier:CellIdentifier] autorelease];  

        if (0 == indexPath.row) {  

                cell.textLabel.text = @"好的"; //cell的text内容  

                UIView *lbl = [[UIView alloc] init]; //定義一個label用于顯示cell之間的分割線(未使用系統自帶的分割線),也可以用view來畫分割線  

                lbl.frame = CGRectMake(cell.frame.origin.x + 10, cell.frame.size.height - 5, cell.frame.size.width - 20, 1);  

                lbl.backgroundColor =  [UIColor lightGrayColor];  

                [cell.contentView addSubview:lbl];  

                [lbl release];  

            }  

            UILabel *label = [[UILabel alloc] init]; //定義一個在cell最右邊顯示的label  

            label.text = @"Dark0921";  

            label.font = [UIFont boldSystemFontOfSize:14];  

            [label sizeToFit];  

            label.backgroundColor = [UIColor clearColor];  

            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {  

                label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 10,\  

                                        12, label.frame.size.width, label.frame.size.height);  

            } else {  

                label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 20,\  

            [cell.contentView addSubview:label];  

            label.textColor = [UIColor grayColor];  

            [label release];  

        }  

        else if (1 == indexPath.row){  

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //顯示最右邊的箭頭  

            cell.textLabel.text = @"添加好友";  

        }     

    }  

    return cell;  

}  

本文轉自 卓行天下  51CTO部落格,原文連結:http://blog.51cto.com/9951038/1769777,如需轉載請自行聯系原作者

繼續閱讀