现在的位置: 首页 > 综合 > 正文

设置TTLauncherView的行高

2013年07月13日 ⁄ 综合 ⁄ 共 948字 ⁄ 字号 评论关闭
今天用TTLauncherView做应用的首界面,发现TTLauncherView默认是以9宫格方式显示,但我的首页只有6个按钮,只需要显示2行。开始只是将TTLauncherView的高度设置为iphone只视高度的一半,却发现空了一行,而有内容的两行却挤在了一起。查看TTLauncherView的源码,发现行数(rowCount)为只读,同时被定义为始终3行显示。于是更改此字段属性。
打开Three20源码,路径:附加在我工程中的Three20UI.xcodeproj工程下 Source/Launcher/ 目录.

 
1、TTLauncherView.h
将原属性的只读去掉:
即,将 @property (nonatomic, readonly) NSInteger rowCount;
改为 @property (nonatomic) NSInteger rowCount;

2、 TTLauncherView.m
添加声明:@synthesize rowCount = _rowCount;
在- (id)initWithFrame:(CGRect)frame {}中加入初始值:self.rowCount = 3;
注释掉:
- (NSInteger)rowCount {
  if (!_rowCount) {
    _rowCount = floor(self.height / [self rowHeight]);
  }
  return _rowCount;
}

新增属性定义:
- (void)setRowCount:(NSInteger)rowCount {
    if (_rowCount != rowCount) {
        _rowCount = rowCount;
        //_rowCount = 0;
        TT_RELEASE_SAFELY(_buttons);
        [self setNeedsLayout];
    }
}

3、调用文件 MyViewController.m
TTLauncherView  *_menuView = [[TTLauncherView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 220)]; 
    _menuView.delegate = self;
    _menuView.columnCount = 3;
    _menuView.rowCount = 2;  

抱歉!评论已关闭.