UITableView练习二之Dynamic Prototypes练习

#import <UIKit/UIKit.h>

@interface MyTableViewController : UITableViewController


@end
<pre name="code" class="objc">#import "ViewController.h"

@interface MyTableViewController ()

@end

@implementation MyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* indentifier = indexPath.row % 2 == 0?@"d1":@"d2";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (cell) {
        UILabel* l =(UILabel*) [cell viewWithTag:1];
        l.text = [NSString stringWithFormat:@"第%ld行%@",(long)indexPath.row,l.text];
        NSMutableAttributedString *richTask = [[NSMutableAttributedString alloc] initWithString:l.text];
        NSDictionary *urgentAttributes = @{NSFontAttributeName:[UIFont fontWithName:@"Courier" size:24],
                                           NSStrokeWidthAttributeName:@2.0};
        [richTask setAttributes:urgentAttributes range:NSMakeRange(0, 3)];
        l.attributedText = richTask;
    }
    return cell;
}
@end


 
 

实现步骤

1,新建工程,删除storyboard里面内容,新增UINavigationBarController,并且指向为启动。

2,选择UITableView,设置ProtoTypeCells = 2,并且设置他们的indentifier为d1,d2

3,点击第一个ProtoTypeCell,然后拖动组件,Label和Button,设置他们tag =1,2。第二个ProtoTypeCell也一样。

4,设置他们的约束,以便支持所有宽度的屏幕。

上面设置特殊字体的几行代码没看懂,copy过来的,明天研究下....


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值