首页 > 其他 > 详细

UITabeViews---设置字体格式,大小,颜色

时间:2015-05-23 14:15:51      阅读:336      评论:0      收藏:0      [点我收藏+]

效果图:

技术分享


UITableView设置每行显示的内容,字体格式,大小,颜色

首先设置根视图控制器:

AppDelegate.m文件


#import "AppDelegate.h"

#import "JRTableViewController.h"


@interface AppDelegate ()


@end


@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    

    JRTableViewController * tableVC=[[JRTableViewController alloc]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 {

    [super viewDidLoad];

    

    self.tableView.rowHeight=100;

    

    //加载数据

    [self _loadData];

    

    

}


#pragma mark - 加载 tableView 数据

- (void) _loadData

{

    self.dataArray=[UIFont familyNames];  //每行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=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identy];

    }

    cell.textLabel.text=self.dataArray[indexPath.row];

    cell.textLabel.font=[UIFont fontWithName:cell.textLabel.text size: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 {

    [super didReceiveMemoryWarning];

}



@end



UITabeViews---设置字体格式,大小,颜色

原文:http://blog.csdn.net/qq_27364431/article/details/45933729

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!