设置TTLauncherView的行高

今天用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; 


完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值