#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过来的,明天研究下....