UITableView练习二之Dynamic Prototypes练习
来源:互联网 发布:ssh 端口修改 编辑:程序博客网 时间:2024/06/04 23:30
#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过来的,明天研究下....
0 0
- UITableView练习二之Dynamic Prototypes练习
- UITableView练习三之Static Cells
- UITableView练习-省市区
- uitableview持续练习
- UITableView练习一
- JavaScript练习二之Tabs
- Python 练习册之二
- javaee之JQuery练习二
- python编程练习之二
- 《刻意练习》读书笔记之二
- 练习(二)
- 练习二
- 练习二
- 第二十二篇:UITableView练习代码
- 读经典之TCPL练习二
- 【java编程】GUI之综合练习(二)
- [数据存储之二]NSUserDefaults练习
- [多线程之二]-NSOperation练习
- GitLab致开源项目维护者的一封信
- 利用java来访问网站
- Uva Tian Ji -- The Horse Racing
- 【DP+矩阵优化】[HNOI2008][HYSBZ/BZOJ1009]GT考试
- 有符号数与无符号数之间运算问题
- UITableView练习二之Dynamic Prototypes练习
- shell加密工具shc的安装和使用
- Android 布局优化
- android布局属性详解
- 时间选择器TimePickerDialog
- JQury中设置元素自定义动画animate方法
- iOS Block 的具体使用
- mac快捷键总结
- 单例设计模式