UITabeViews---设置字体格式,大小,颜色
来源:互联网 发布:python 定时发送邮件 编辑:程序博客网 时间:2024/05/20 18:52
效果图:
UITableView设置每行显示的内容,字体格式,大小,颜色
首先设置根视图控制器:
AppDelegate.m文件
#import "AppDelegate.h"
#import "JRTableViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
JRTableViewController * tableVC=[[JRTableViewControlleralloc]init];
self.window.rootViewController=tableVC;
return YES;
}
自定义的JRTableViewController.m文件
#import "JRTableViewController.h"
//定义宏
#define jrRandomColor [UIColor colorWithRed:arc4random_uniform(10)*0.1 green:arc4random_uniform(10)*0.1 blue:arc4random_uniform(10)*0.1 alpha:1]
@interface JRTableViewController ()
//数据存储
@property (nonatomic,strong)NSArray * dataArray;
@end
@implementation JRTableViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.tableView.rowHeight=100;
//加载数据
[self_loadData];
}
#pragma mark - 加载 tableView 数据
- (void) _loadData
{
self.dataArray=[UIFontfamilyNames]; //每行cell内显示的内容
}
//创建JRTableViewController时,自动生成代理方法
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count; //返回数组的行数
}
#pragma mark - 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identy=@"JRTable";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identy];
if (!cell)
{
cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identy];
}
cell.textLabel.text=self.dataArray[indexPath.row];
cell.textLabel.font=[UIFontfontWithName:cell.textLabel.textsize:16];
//设置字体颜色
if(indexPath.row%2==0)
{
cell.textLabel.textColor=jrRandomColor; //宏
}
return cell;
}
//设置每一行的高度
/*
第 0行 高度 100
第 1行 高度 50
第 2行 高度 100
第 3行 高度 50
第 4行 高度 100
第 5行 高度 50
*/
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row%2==0)
{
return 100;
}
else
{
return 50;
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
@end
- UITabeViews---设置字体格式,大小,颜色
- android设置Spinner字体颜色,格式,大小
- MFC——设置静态文本 大小 字体格式 颜色
- webview设置字体颜色、大小
- MFC操作——设置静态文本 大小 字体格式 颜色
- python设置Console大小以及字体颜色
- UISearchbar设置placeholder字体颜色大小
- 设置button字体颜色和大小
- 换行的字体的设置大小颜色
- texeFielf设置placeholder字体颜色和大小
- markdown设置字体颜色、大小、背景
- html设置字体显示颜色以及大小
- Android 使用 html设置字体颜色大小
- 如何修改wordpress文章字体格式、字号大小、字体颜色
- textview设置不同格式字体颜色
- 设置导航栏标题,字体颜色,大小 背景颜色 等
- C# 文档编辑器设置字体、大小、字体格式
- MyEclipse设置字体格式和大小,及字体推荐
- 文本语言模型的参数估计-最大似然估计、MAP及贝叶斯估计
- 数据库第4个实验工作量蛮大的
- https://leetcode.com/problems/search-for-a-range/
- 【原创】wince bluebooth设备编程札记
- HTML5新特性之Communication
- UITabeViews---设置字体格式,大小,颜色
- 用例规约
- Linux tar 解压命令总结
- c# 调用Web Service的问题:The operation 'XXX' could not be loaded because it has a parameter...
- swustoj2521 acmer的约会—状态压缩+bfs
- AutoHotkey数组例子
- linux awk命令详解
- https://leetcode.com/problems/sqrtx/
- 【原创】windows 进程管理