グループ化された UITableView がある場合、その端に灰色がかった境界線/バッファーが付いています。このバッファーの大きさ、または同等に、バッファー内の実際の白いセルの大きさを知る方法はありますか?
3313 次
1 に答える
3
これは、グループ化されたUITableViewの左マージンと右マージンを削除する方法です。UITableViewCellをサブクラス化するだけです。マージンを0以外にしたい場合は、必要に応じてsetFrameメソッドを変更するだけであることに注意してください。
//In CustomGroupedCell.h
#import <UIKit/UIKit.h>
@interface CustomGroupedCell : UITableViewCell
@property (nonatomic, weak) UITableView *myTableView;
@end
//In CustomGroupedCell.m
#import "CustomGroupedCell.h"
@implementation CustomGroupedCell
@synthesize myTableView = _myTableView;
- (void)setFrame:(CGRect)frame
{
frame = CGRectMake(- [self cellsMargin] , frame.origin.y, self.myTableView.frame.size.width + 2 *[self cellsMargin], frame.size.height);
self.contentView.frame = frame;
[super setFrame:frame];
}
- (CGFloat)cellsMargin {
// No margins for plain table views
if (self.myTableView.style == UITableViewStylePlain) {
return 0;
}
// iPhone always have 10 pixels margin
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return 10;
}
CGFloat tableWidth = self.myTableView.frame.size.width;
// Really small table
if (tableWidth <= 20) {
return tableWidth - 10;
}
// Average table size
if (tableWidth < 400) {
return 10;
}
// Big tables have complex margin's logic
// Around 6% of table width,
// 31 <= tableWidth * 0.06 <= 45
CGFloat marginWidth = tableWidth * 0.06;
marginWidth = MAX(31, MIN(45, marginWidth));
return marginWidth;
}
@end
于 2012-07-26T17:07:52.673 に答える