IMOStyledTableViewController 0.0.4

IMOStyledTableViewController 0.0.4

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014 年 12 月

Frederic Cormier 维护。



  • 作者
  • Frederic Cormier

一个易于自定义样式的 Table View Controller。

当此

//style.imo
NavBarTintColor                 0.600   0.492   0.331   1.000
BackgroundColor                 #CDC3B9
TextLabelFont                   HelveticaNeue-Bold       17.0

TextLabelTextColor              #3F3B35

TopGradientColor                1.000   0.995   0.995   1.000
BottomGradientColor             0.825   0.780   0.724   1.000

SelectedTopGradientColor        #8A6F48
SelectedBottomGradientColor     #725C3C

生成此

screenshot screenshot

安装

手动

将 IMOStyledTableViewController 目录复制到您的项目中

使用

A - 样式表

1 - 在您的项目中添加名为 style.imo 的文件,包含所有您想自定义的属性(有关语法和哪些属性可用,请参阅 wiki 或示例)。

2 - 使您的表视图控制器成为 IMOStyledTableViewController 的子类

#import "IMOStyledTableViewController.h"

@interface MyStyledTableViewController : IMOStyledTableViewController

3 - 如此实例化

MyStyledTableViewController *mstvc = [[MyStyledTableViewController alloc] initWithStyle:UITableViewStyleGrouped
                                                                             styleSheet:nil];

4 - 在您的 - tableView:cellForRowAtIndexPath: 方法中,在调用 UITableViewCell 之前,使用以下代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    IMOStyledCell *cell;
    cell = [IMOStyledCell cellForTableViewController:self 
                                         atIndexPath:indexPath 
                                               style:IMOStyledCellStyleValue1];
    /*
        Do whatever you have to do with your cell   
    */
    return cell;
}

请注意,您无需处理 dequeuing cells 和声明 cell 标识符,IMOStyledTableViewController 会为您处理这些。

B - 字典

尽管在所有 Table View Controllers 都应使用相同样式时使用样式表策略是个好主意,但您可能使用字典方法自定义那些可能与其他不同的非常特殊 Table View Controller。
使用 -initWithStyle:styleSheet: 方法,并传递一个键/值字典

NSDictionary *plainStyleSheet = 
@{
IMOStyledCellBackgroundImageKey: [UIImage imageNamed:@"clouds.png"],
IMOStyledCellNavBarTintColorKey:[UIColor colorWithRed:0.145 green:0.185 blue:0.359 alpha:1.000],
IMOStyledCellTopGradientColorKey:[UIColor colorWithWhite:0.945 alpha:0.220],
IMOStyledCellBottomGradientColorKey:[UIColor colorWithRed:0.628 green:0.632 blue:0.684 alpha:0.570],
IMOStyledCellTextLabelFontKey:[UIFont fontWithName:@"HelveticaNeue" size:18.0],
IMOStyledCellTextLabelTextColorKey:[UIColor whiteColor],
IMOStyledCellTopSeparatorColorKey:[UIColor colorWithRed:0.771 green:0.793 blue:0.820 alpha:1.000],
IMOStyledCellBottomSeparatorColorKey:[UIColor lightGrayColor]
};

 MyCustomStylePlainViewController *mcspvc = [[MyCustomStylePlainViewController alloc]
                                                 initWithStyle:UITableViewStylePlain
                                                    styleSheet:plainStyleSheet];

键和样式属性

样式属性名称由在 IMOStyledCellKeys.h 中声明的键名称组成,去掉前缀 "IMOStyledCell" 和后缀 "key"
因此,"IMOStyledCellTopGradientColorKey" 给出 "CellTopGradientColor"

style.imo 参数和语法

您可以使用多种方式输入颜色

  • RAMA 颜色,范围在 0 到 1.0 之间
  • 十六进制颜色 6 位数字
  • 六位十六进制颜色

对于字体,传递格式为浮点的字体名称和大小

对于图像,传递名称,无需引号,无需扩展名

有效的布尔值有:YES、yes、y、TRUE、true、t、NO、no、n、FALSE、F、f 以及当然的 0 或 1、2、3、4、5、6、7、8、9。
(详情请参见 NSString boolValue

示例
NavBarTintColor                 0.600   0.492   0.331   1.000   //RGBA
BackgroundColor                 0xCDC3B9                        // Hex, 6 digits only
BackgroundImage                 clouds                          // Image Name - Doesn't need extension
TextLabelFont                   HelveticaNeue-Bold       17.0   // Font name and size
TextLabelTextColor              #3F3B35                         // Hex, 3 or 6 digits
RoundedGroupedCellIOS6Style     NO                              // rounded cells - nostalgia mode

IMOStyledTableViewController 包含几个预定义的单元格子类

  • IMOStyledCell
  • IMOStyledEditCell
  • IMOStyledNoteViewCell
  • IMOStyledImageCell

查看示例代码了解如何使用这些子类

可用的属性

属性 注释
RoundedGroupedCellIOS6Style iOS 7 或更高版本:分组样式中的圆角单元格
NavBarTintColor 导航栏和 IMOStyledNoteViewCell 的工具视图颜色
BackgroundImage 表格视图控制器背景图名称
BackgroundColor 表格视图控制器的背景颜色
TopGradientColor 单元格的上渐变颜色
BottomGradientColor 单元格的下渐变颜色
SelectedTopGradientColor 选中单元格的上渐变颜色
SelectedBottomGradientCo 选中单元格的下渐变颜色
TopSeparatorColor 单元格顶部分隔线颜色
BottomSeparatorColor 单元格底部分隔线颜色
TextLabelTextColor 与 UITableViewDataSource 中的 UITableViewCell 一样
DetailTextLabelTextColor 与 UITableViewDataSource 中的 UITableViewCell 一样
TextLabelFont 与 UITableViewDataSource 中的 UITableViewCell 一样
DetailTextLabelFont 与 UITableViewDataSource 中的 UITableViewCell 一样
UseCustomHeader 属性名已经说明了一切
HeaderFont 如果 UseCustomHeader 是 YES
HeaderTextColor 如果 UseCustomHeader 是 YES
UseCustomFooter 猜猜看?
FooterFont 再次
FooterTextColor 无注释
TextFieldFont 这是 IMOStyledEditCell 中的文本字段
TextFieldTextColor 这是 IMOStyledEditCell 中的文本字段
TextCaptionFont TextCaption 是 IMOStyledEditCell 中文本框左侧的标签
TextCaptionTextColor 相同
NoteViewFont 具有多行编辑的注释视图单元格
NoteViewTextColor 猜猜看
NoteViewLineColor 猜猜看
PlaceHolderFont 根据您的喜好更改
PlaceHolderTextColor 根据您的单元格颜色…您可能想更改此选项

许可证

版权(C)2013 Frederic Cormier

特此授予任何人免费获得此软件和相关文档文件的副本(“软件”),以便在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许拥有软件的人将其用于此目的,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或实质部分中。

软件按“原样”提供,除非另有说明,否则不含任何明示或暗示的保证,包括但不限于对适销性、适用于特定目的和无侵权的保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论该索赔、损害或其他责任是由于合同、侵权或其他原因引起,并且与软件、软件的使用或其他交易有关。