[英]How to adjust position of textLabel, detailTextLabel and switch in tableview?
我在tableview單元格中有textLabel,detailTextLabel,UISwitch。 我想調整它們的位置。 我怎樣才能做到這一點? 我已經調整了單元格的高度。
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(200, 10, 50, 30);
cell.accessoryView = switchView;
上面的代碼不適用於切換。 它始終顯示在同一位置。
您可以自定義自己的UITableViewCell(例如MyTableViewCell)並調整layoutSubviews中的控件。
例如:
- (void)layoutSubviews {
[super layoutSubviews];
// Adjust size
self.imageView.bounds = CGRectMake(0,0,44,44);
// Adjust position
self.textLabel.frame = CGRectMake(self.textLabel.frame.origin.x,
self.textLabel.frame.origin.y - 10,
self.textLabel.frame.size.width,
self.textLabel.frame.size.height);
}
您將需要將其作為subView添加到單元格的內容視圖中,如下所示:
[[cell contentView] addSubView:switchView];
和switchView的x,y應該相對於tableViewCell。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.